Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send data to created activity on Android

Tags:

android

I need to send data from EditText in activity A to Activity B. I tried:

Intent intent1=new Intent(A.this,B.class);
intent1.putExtra("fromA", "text");
startActivity(intent1); 

But It doesn't work, because activity B has android:launchMode="singleTask" and was created before.

How else, can I send data?

like image 225
user1884872 Avatar asked Dec 15 '22 15:12

user1884872


1 Answers

You override onNewIntent() in the Activity B and receive the intent in that method.

Like below code:

@Override
protected void onNewIntent(Intent i)
{
  String s = i.getStringExtra("fromA");
}

In the above code you will get value to s from Activity A.

like image 199
TNR Avatar answered Jan 05 '23 04:01

TNR