Thursday, June 18, 2015

Passing Data Between Activities in Android

passing data from one activity to another activity in android using intent.

Suppose two Activity : FirstActivity and SecondActivity. if we want to send data from FirstActivity  to SecondActivity  then we move from another activity using Intent 

We Send data in key-value form.

Convert timestamp to date and time in android

Here Timestamp means UNIX timestamp,convert to date and time in android. suppose timestamp is 1434624342http://www.currenttimestamp.com/) and show into DD-MM-YYYY and HH:MM  format.

           long time=1434624342;
           Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    cal.setTimeInMillis(time);
    String date = DateFormat.format("dd-MM-yyyy hh:mma", cal).toString();

Sunday, February 22, 2015

Load URL in WebView Android

Open URL in WebView:

In android open website by using WebView. WebView use for display website content in android like as browser.

What is WebView:

WebView use for open website in android like browser. WebView display all website data in andriod.
Like this URL open in WebView http://invokecode.blogspot.in/

WebView in Android
WebView in Android

Tuesday, February 17, 2015

Create Custom ListView in Androd

What is Custom ListView:

custom list view means custom Layouts and show custom Item in listview. in simple listview use only text or image show in list using ArrayAdapter but in custom listview we use CustomAdapter.
custom listview may be many image or text.

Create Custom ListView in Android
Custom ListView in Android

Why Use Custom Listview: 

as we discuss simple listview contain only simple layout so we need custom layout for custom listview. custom listview contain images and text and many more.

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 !!


Tuesday, December 9, 2014

Splash Screen in Android

What is Splash Screen?

when application start then first screen,called   "Splash Screen"  also called " launching screen ." it may be logo or introduction of application and show for few seconds.

     

 int splashTime=5*1000;// 5 second


 Thread splashThread=new Thread(new Runnable() {


@Override

public void run() {

// TODO Auto-generated method stub
try {
Thread.sleep(splashTime);  // sleep for 5 seconds
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// after 5 seconds it will go to next screen
finish(); // never back to splash Screen
Intent i=new Intent(SplashScreen.this, HomeActivity.class);
startActivity(i);
}
});

                      splashThread.start();


Alternate Way:

   new android.os.Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
             finish(); // never back to splash Screen
Intent i=new Intent(SplashScreen.this, HomeActivity.class);
startActivity(i);
            }

        }, splashTime);


Splash Screen Android
Splash Screen Android
visit here more tutorials:    http://www.invokecode.com 
Thank You !!

Sunday, December 7, 2014

Application Class in Android

What is Application Class in Android

create class by extend Application, in which we put data like String, Array or other type and access in All Activities.

public class MyApplication extends Application {
public static MyApplication Instance = null;

public static MyApplication getInstance() {
return Instance;
}

public String name="";     // example save name  in this class

public String getName() {
return name;                            // create getter and setter Method of name.
}

public void setName(String name) {
this.name = name;
}


}


Save Value in Application Class

MyApplication.getInstance().setName("Hello"); // save Hello name 


Get Save Value in Application Class


MyApplication.getInstance().getName();   // get save  name

Register Application class in Manifest

inside application tag

 <application
        android:name=".MyApplication" // application class name
        .............................................................
        ..............................................................
...</application>






Click here www.invokecode.com for Android Application Development Tutorial.