Monday, May 28, 2012

Pass Data Between Activities in Android?: Part 2

 You can pass data between to Activities using Intent.Example:

   In Activtiy SenderActivity.java:



//Create new Intent Object, and specify class Intent intent = new Intent(); intent.setClass(SenderActivity.this,Receiveractivity.class); //Set your data using putExtra method which take //any key and value which we want to send intent.putExtra("senddata","This is From SenderActivity.class"); //Use startActivity or startActivityForResult for Starting New Activity SenderActivity.this.startActivity(intent);


   In Activtiy SenderActivity.java :



//obtain Intent Object send from SenderActivity Intent intent = this.getIntent(); /* Obtain String from Intent */ if(intent !=null) { String strdata = intent.getExtras().getString("senddata"); // DO SOMETHING HERE } else { // DO SOMETHING HERE }



Download Source Code: Intentpassdata








0 comments:

Post a Comment

 
Powered by Blogger