Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass data to a single task activity after the first time it loads

I have an Activity that is a single task so I guess on create only gets called once. I want to pass some parameters from another activity. using Intent, i am putting extras but when I read them in the single activities onResume, the data is not there.

I need a way to pass data to a single task activity or restart it.

edit

To clarify. The problem is my activity uses Single Task as a launch mode in the manifest. I think this means oncreate only gets called once which is why i am trying to get the parameters in onResume.

When I resume my single task activit, I am unable to get any params added to the intent in the previousd activity because it does not start it but simply resume it

like image 374
code511788465541441 Avatar asked Dec 28 '25 07:12

code511788465541441


2 Answers

Use onNewIntent() with single-instance Activity. Calling getIntent() in onResume() for a single-instance Activity will return the Intent that originally started the Activity, not the Intent that the Activity just received. To ensure that getIntent() always returns the last-received Intent in a single-instance Activity, use setIntent() to store the last-received Intent.

This is documented in the reference documentation for onNewIntent()

like image 178
Joe Malin Avatar answered Dec 30 '25 21:12

Joe Malin


if you are trying to pass data to an activity that was started with single task and the activity is currently up then you need to override onNewIntent when a new intent comes into that activity this is where it goes

like image 44
tyczj Avatar answered Dec 30 '25 20:12

tyczj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!