How can I know what Activity has started the current Activity? Is there any specific method like, i.e. getIntent().getCallerActivity() or the only way is saving some information within the Intent using putExtra()?
Thanks.
There's getCallingActivity which you can use to get the name of the calling activity if you started the sub-activity with startActivityForResult.
Related
Can i call second activity from current activity without use intent? and why use intent, why not call second activity direct from the first activity?.
What does intent do in android?
Because to start any new Activity Android must have to go through the life cycle of an Activity. So it is necessary to use intent.
http://developer.android.com/reference/android/content/Intent.html
you can't ,see this link android is designed in this way to launch another activity
Intent says to Android you need open a new activity. Always when you need open a new Activity, you need "alert" the S.O before. Because of this we use Intent.
Activities doesn't work like a simple class, when we just instantiate.
This link will help you
http://www.vogella.com/tutorials/AndroidIntent/article.html
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!
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.
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)
I want to pass the WebView from One activity to another Activity.
how to do that. I referred How do I pass an object from one activity to another on Android?
but still not getting any idea for this. Please help me to get this....
Sounds to me like you may want a broadcast receiever...
try looking here: BroadcastReceiver
That will let one activity send a message to another
either u try to use finish() an the passed Activity or you simply call finish() in the activity after it's done with it's calculations
Are you sure you want that in an Android activity, not just a normal Java class?
Hi i am new to Android application development.In my Application i have two activity Activity1 and Activity2.From activity1 i call Activity2 as Intent.I want to access activity1 from this Activity(activity2) without going to first activity is there any posible way?Pls guide me
The only thing which make sence is passing data from Activity 1 to Activity 2. To do it just pass some data through the intent:
intent.putExtra("key", "Your data here");
in second activity:
String data = getIntent().getExtra("key");
If this is not the case, then your task is wrong somewhere. When activity gone background, there is no sence to interact with it.
No, there isn't. Activity1 might even have been shut down.
If you want to pass DATA between the two activities, that's of course doable. Either by passing data on with the intent, by using http://developer.android.com/reference/android/content/SharedPreferences.html or any other storage you can access from both activities.
If from your second activity wants to change something on the previous one, then, instead of using
startActivity(...);
you should use
startActivityForResult(...);
Maybe this link can help.
So you have the scenario where you start activity B from activity A and you want to change some parameters when activity B is done ( your changes can't be propagated in real time because you can't be sure what is the state of activity A ). So the best way to implement this is to use activity result - for more info about it check Android: Capturing the return of an activity
I want to find out which activity started my activity in android. I can get the intent that started the activity using getIntent() but I am not able to find out which activity started the intent in the first place.
Use getCallingActivity()
Note: if the calling activity is not expecting a result (that is it did not use the startActivityForResult(Intent, int) form that includes a request code), then the calling package will be null
You can use ActivityCompat.getReferrer() for this purpose.