Friday, January 9, 2015

AsyncTask in Android

AsyncTask in Android:

AsyncTask in Android
AsyncTask in Android


Asynctask  in android use for network operation like upload data  and get data from server means "Network Related Task" If without use of AsyncTask we do network related task then "RunOnUIException "  error Occur.

Create AsyncTask  by extend Async , Params,Progress and Result  can be chnage according to need, likes if need String Type data then change String.

AsyncTask method  onPreExecutedoInBackgroundonProgressUpdate and onPostExecute and for acess UI mean without network related task like set value in textbox or show progress dialog etc. onPreExecute and onPostExecute Only for UI. and for "Network Related Task" use doInBackground. method.

for short operation we use AsyncTask and if need large data then use  ExecutorThreadPoolExecutor and FutureTask. easy manage UI and Background related work in AsyncTask but In case of Thread for UI we need runOnUiThread method or handler.

 Create AsyncTask:

                              class AstncTask extends AsyncTask {
                                      @Override
protected void onPreExecute() {
// TODO Auto-generated method stub
                                           super.onPreExecute();
                                          // For UI  
 }

                                           @Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
                                               //"Network Related Task"
}

                                            @Override
                                              protected void onPostExecute(String result) { 
                                               super.onPostExecute(result);
                                               //after doInBackground it call 
                                                 // UI   related work
                                              }
}

Call AsyncTask

new AsyncTask().execute();

visithttp://invokecode.com/  for More Tutorials 

if any query related this tutorial  then please comments !!

Thank You !!

Saturday, January 3, 2015

Progress Dialog in Android

show progress dialog in android:

ProgressDialog pDialog; //initialize
pDialog = new ProgressDialog(context); //  pass context or activity.this
pDialog.setMessage(“Please wait…”);// set Message
pDialog.show(); // showing
pDialog.dismiss(); // dismiss

Email Validation in Android:

Email Validation in Android:


Email validation in android, simply we match Pattern like name@gmail.com  format…
String.matches  if match then email format is valid else not valid format..
for email Pattern:
String pattern= “[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+”;
if (ourEmail.matches(pattern)) {
Email valid format
}
else{
“invalid email  format!!
}

Custom Dialog in Android

Show custom dialog in android:

Custom Dialog in Android
Dialog dialog=new Dialog(MainActivity.this);
// inflate layout here
dialog.setContentView(R.layout.custon_dialog_layouts);
dialog.setTitle(“Custom Dialog”);
// define custom dialog button , edittext etc. here and their click
like example
Button button=(Button) dialog.findViewById(R.id.cancelDialog);
// Button = dialog nanem.related find id//
// dialog.dismiss for dismiss dialog
dialog.show();
Note:if any issue to implement then comment.
Thank You !!