0

I have two Activity: Activity1 and Activity2 Activity1 start Activity2 and I want to send a result from Activity2 to Activity1, but I can't use startActivityForResult() cause the lanuchmode of Activity1 is singelInstance. Are there any ways to send a callback from Activity1 to Activity2?(So far as I konw, one is send BroadCaseReceiver, the other is made a static param in Activity2)

Many thanks!

Wendy Chen
  • 161
  • 1
  • 1
  • 8

2 Answers2

0

startActivityForResult not working properly with launchMode singleInstance

A similar question, it suggested using saved instance state and or saving information to a db/global storage.

onActivityResult do not fire if launch mode of activity is singleInstance

Proposes that you use a different type, replacing singleInstance with singleTask

You could extend the activity you want to launch and force its type to a different one for this scenario, leaving the original as SingleInstance.

Community
  • 1
  • 1
Emile
  • 11,451
  • 5
  • 50
  • 63
0

It will not work to use broadcast to communicate between two Activities. Only one of the Activities will ever be active at a time. It does make sense to use it to communicate between an Activity and a Service, for example.

Generally you can use intent extras to pass information to the next Activity. I.e, using putExtra.

(java.lang.String, android.os.Bundle)

Swapnil Kale
  • 2,620
  • 2
  • 23
  • 21
  • I tried extra, there is one question: I can get the callback from extra in Activity2, but getApplicationContext() is null cause this extra is from Activity1 and Activity1 is in onStop state. – Wendy Chen Aug 20 '12 at 09:40