I am already using a pending intent..So if I use another intent and start that intent it goes to a new activity..I want to avoid that..So without using intents I want to pass data from one activity to another possible?
You can use static Method to get data from one activity to another activity.Below is sample code
First Activity
public class First extends Activity {
static First INSTANCE;
String data="FirstActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
INSTANCE=this;
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public static First getActivityInstance()
{
return INSTANCE;
}
public String getData()
{
return this.data;
}
}
Second Activity:
public class Second extends Activity {
String data;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
data=First.getActivityInstance().getData();
Toast.makeText(Second.this,"Data from first activity is"+data, 1).show();
}
}
Hope it helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With