for example my App have 3 activity main Activity A,and other B ,C,so i want to know if i can know B or C Activity is running,i know how to check Main Activity A using PackageManager. thank you
you can use ActivityManager to get information about running activities.
We can use Toast.maketext to know the Activity B or C is started or not
Related
Can any one tell me the the working of Intent.FLAG_ACTIVITY_FORWARD_RESULT Live Example
now what I am doing just creating three activity that are A,B,C
so When I am Launching Application from activity A and from A I am Starting Activity B with startActivityForResult(Activity B) and there In B Activity I am starting activity C with Intent.FLAG_ACTIVITY_FORWARD_RESULT and finishing B Activity,so now from there in Activity C When I finished to Activity C it gives result back to the Activity A in onActivityResult().
So i want to know that is this the purpose of using this flag or that is something different and if I am wrong please let me know.
and please try to give answer with example.
Virendra, your assumptions are correct. This gist demonstrates a simple use case: https://gist.github.com/mcelotti/cc1fc8b8bc1224c2f145. Please note the use of setResult() in ActivityC before it is finished.
The solution is already on the stackoverflow .I hope you may understand the logic .
I suggest you to go with this solution flag activity #stackoverflow.
In my app, whenever calling the finish() method, wherever it was, I am not taken to the previous activity, rather I am directed to mainActivity.
finish();
My aim is, showing the user the activity just before the current activity he is seeing.
Question 1 : How can I make finish() always take me to the activity before ?
Question 2 : Does this work using another workaround other than finish() ?
Question 3 : How to check the stack of activities and decide accordingly which one to go to ?
If you have written finish in each intermediate activity, that means you are removing the activity from the stack, hence on finishing an activity you are taken to the last non-finished activity, hence write finish() in only that activity which you do not want to see until the same workflow is followed and its onCreate() is called
if you start activity c from b and b from a if you use the back button on your phone at activity c it will go to b and back button press in b it will show a. if you use finish in all the 3 activities what happens is a calls b and a is finished and b calls c and b is finished so when you use finish in c it will not have b to show. so you have to tell where you are placing your finish based on some condition or a button click or just before starting a new activity, post your code and we will help you.
I have a problem cause when I go to different activities using startActivity function,
they always get created from scratch. Even if activity A was visited before, when I go to activity B and then A again, activity A is created again.
The problem is with back button, cause if I go to Activity A then B then A and then B,
in order to close the application I have to press back button 4 times.
I guess that it shouldn't act like it and user should be able to go to activity A when first pressed back button and the second press should close the application.
How to solve this issue?
Greetings
If you have activity transitions like:
Activity A -> Activity B
Activity B -> Activity A
and you want the user to go back to the same instance of Activity A in this case, maybe you just need to call finish() in Activity B after you call startActivity() for Activity A?
If this isn't helpful, please give us more information about what you are trying to do.
make sure you implement onSaveInstanceState and be prepared to restore your activity from a Bundle in onCreate. that's how you re-establish where you were when you return to an activity.
add launcheMode="singleTask" to your activity in the manifest
You need to set FLAG_ACTIVITY_SINGLE_TOP to your intent for launching activity A. Doing so will cause your previously created activity to re-use. Make sure you do handle your afterwards intents in onNewIntent method. For more info.
You need to set the flag FLAG_ACTIVITY_REORDER_TO_FRONT when you start activity A from B or vice versa, like
i = new Intent("....ActivityAorB");
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
I've tried solutions proposed so far, however they didn't do it for me.
What did however, is using flag FLAG_ACTIVITY_CLEAR_TOP while starting activities.
Thanks for pointing me in the right direction though.
Am having an application contains activity A,B,C and A is launched from the browser and B is launched from A, a count timer running on A launches an activity C if the timer hits. Could any one plz tell the stack order for the activity of this application. either A->B->C or A->C->B. However now the visible activiy should be C if i press back key from C which should display either A or B ?
Thanks in advance.
You can try to launch B from A and C from A with
startActivityFromChild(this, intentOfC, REQ_CODE_FOR_C);
I'm not sure it may be useful to you.
This order is depends upon the launch mode of your activity
I want to know which activity calls current activity.I have three activity namely A,B and C. i am calling activity C from A or B. In activity C i want to know which activity calls A or B.
I used bundle to identify activity but i dont want this.. Is any other smart way to find my case?
Thanks in Advance...
getCallingActivity()