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.
Related
I have three activities A, B and C.
A --> B --> C. activity B isn't shown to the user, its calling an api and gathering some information. Should the user hit back I'm hoping for it to go back to A, but not sure how this can be done?
I've already tried coroutines to get around this issue and I've not had much look.
Result is that the back button when pressed continues back to activity C and never gets back to activity A.
Any advice would be great.
Thanks
You can call finish() on B Activity after startActivity(...) call
startActivity(Intent(this, C::class.java))
this.finish()
Why are you using Activity B at all? I think there is a problem with your design. Look into android architecture components project for a good design guideline. Usually things like api calls need to be done inside classes that do not depend on Activity lifecycle, unless you need the activity lifecycle for your requirement. Android Architecture Components "JetPack"
i'm trying to make an app for nexus 7.
how can i display multiple activity to red area when the button is clicked??
Btn_A call activity A
Btn_B call activity B
Btn_C call activity C
Btn_D call activity D
i'm really need a example for this.
You should use fragments in this case.
You can find some useful examples in the API demos.
Tab activity is the best for that scenario. Please read the below link for tab activity.
http://www.androidhive.info/2011/08/android-tab-layout-tutorial/
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.
I have been searching for an answer but I couldn't find a proper one. The question is that I have a dialog themed activity on top of a normal activity. I would like to force the users to either read and click "OK" to the themed activity which will then transfer them to another dialog themed activity for some further questions or cannot enter the application. So, I would like to exit the application, on back press, and not just finish the themed activity that will reveal the content of my app. How is that possible?
If you start your dialog activity with startActivityForResult() you can send back the result RESULT_CANCELED from the dialog, and upon receiving this (in your main activity) you call finish().
finish() will do the perfect job for you ;)
but make Dialog not cancelable..
Edit (after problem description clarification):
As others said StartActivityForResult could work, with additional trick.
Because of the way you design your App (DialogActivity1->DialogActivity2), it might help to add following line in AndroidManifest file, for all your special dialog-look activities:
android:noHistory="true" or to set flag for intent Intent.FLAG_ACTIVITY_NO_HISTORY before u start DialogActivityN.
Both lines (from manifest or code) will make this actitivies not to stay on android stack, so when your MainActivity get result back, it will be result from last DialogActivity and than depending on result recieved you can either finish() or continue with execution of MainActivity..
when u start activities like this there is no need to call finish() to destroy them, u just start new activity and they will be gone from stack. Of course, in your case, last DialogActivity u will start with StartActivityForResult() and as I explained in previous paragraph MainActivity will do something based on received results.
However making user goes through these dialogs several times at the beginning application, is not something I would consider good practice and it can make your user just give up and go for some less annoying app. (don't get this wrong, it's just my advice to rethink about concept)
Hope you will solve it ;) Cheers
If you know about ActivityforResult then way is easier for you, First you need to start the dialog activity with method startActivityforResult... and then when dialog activity get close by back button you have to close it by Set result. In OnactivityResult method of start activity have to detect the same and close the same if setResult is not as according. Hope you got the point.
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