I have tab view and in one activity from tab i start my A Activity from A i start B Activity how can i in some case go to back in Tab Activity.
I Try Intent.FLAG_ACTIVITY_CLEAR_TOP but it clear my A activity ann all activitys in tab view.
Can anyone give suggestion.
Try using this it might do the job
Intent parentActivityIntent = new Intent(this, ActivityYouWannaGoTo.class);
parentActivityIntent.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(parentActivityIntent);
finish();
start B using startActivityForResult and when you want to go back to first activity set the result to RESULT_OK. In A onActivityResult check if the result is RESULT_OK call finish().
In the manifest file set the launch mode of the activity with the tabs to be singleTop (android:launchMode="singleTop"). After that when you want to go back to the tab activity use the flags Intent.FLAG_ACTIVITY_CLEAR_TOP and Intent.FLAG_ACTIVITY_NEW_TASK.
Related
I have 2 activities (MainActivity,SecondActivity)
I am starting SecondActivity from MainActivity now the situation is when I click onbackpress it's return to MainActivity without finishing the second activity
How I can go back to the second activity without reinitializing the activity again?
I created foreground service to display a notification and added the flag start UpdateCurrent to the pending intent but this cause that Oncreate recalled
what is the solution for this ?
If my understanding of your issue is correct, you need to try this:
Intent.FLAG_ACTIVITY_CLEAR_TOP
Intent.FLAG_ACTIVITY_SINGLE_TOP
And this:
Intent int = new Intent(SecondActivity.this, MainActivity.class);
int.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(int);
When my activity stack is like,
MainActivtiy -> Activity1 -> Activity2 -> Activity3
I need to go 3 back states to reach MainActivtiy from Activity3
I could be able to close opened activities from Activity3 like,
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
But, above code segment closes all activities including MainActivtiy and starts new MainActivtiy. I want to know are there any other options to do the task that I need. I dont want to create new Intent because it drops the data of static methods that I have created in my MainActivtiy.
Please help me, Thanks in advance.
You should use FLAG_ACTIVITY_CLEAR_TOP which will bring the running activity on top and remove all other activities above it
Note : it will trigger the onNewIntent of already running activity otherwise mention launchMode = "singleTask" in activity tag, inside manifest
I'm using this library which is a Wizard.
When user is done with the Wizard and clicks Done button he moves to another Activity.
I have added to Manifest file android:noHistory="true" for the WizardActivity and also when I start the next activity im doing it like this :
Intent intent = new Intent(this, ProjectsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Nevertheless when user click backs he still goes to the WizardActivity. I'd like the user either to exit or go the activity that started the WizardActivity.
Thank you
finish() the activity after launching the other Activity. i.e after startActivity(intent) add finish()
I am having 3 activities. From the third activity, I need to come back to the 1st activity when a GUI button is clicked. I know I can click the "physical" back button 2 times to make this but that is not an option.
So, is there any way I can display the 1st activity, without creating a new instance? I can pass the 1st activity's instance to the third activity, no issue with that.
Use the FLAG_ACTIVITY_CLEAR_TOP in your intent.
From the documentation:
For example, consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.
To use:
Intent intent = new Intent(getBaseContext(), FirstActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Intent intent = new Intent(src_ctxt, dest.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
src_ctxt.startActivity(intent);
This should do it
I think you need to make your activity B singleInstance that if it's already create you don't want to create again, that is launch mode of the activity can be defined in manifest android:launchMode that defines how the activity will be instanciated.
in your case use android:launchMode="singleInstance"
or
You can use flag Intent.FLAG_ACTIVITY_NEW_TASK. If the activity is already running it will bring that to front instead of creating new activity.
I'm new to android. Actually one handler is running in Home Activity A for every 30 sec to check the net connection.
If I'm went to activity C by A->B->C, If there in no net connection at that time, then i want to close Activity B and C, then want to show message box in Activity A.
But My problem is My handler is running for every 30 sec in Home Activity A. But If i was in Activity C or some other Activity how to find which activity is my Application currently focussed now. Then i want to finish those child activities and want to show Home Activity A I have some 9 child activities in Activity B.
I heard about using "FLAG_ACTIVITY_CLEAR_TOP" . I used the code as follows in the handler in Home activity A itself. But got error.
Intent intent = new Intent( ctx, Homepage.class );
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |
Intent.FLAG_ACTIVITY_CLEAR_TOP);
ctx.startActivity( intent );
Here Homepage.class is my Home Activity A and i set that activity in manifest file as
android:launchMode="singleTop"
Please help!
You can start Activity A and close all other activities.
You have to create new intent and add flag FLAG_ACTIVITY_CLEAR_TOP
Intent activityA = new Intent(context, ActivityA.class);
activityA.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.StartActivity(activityA);
this will close all activities that are in the stack and are at the top of activity A
When calling Acitivity C, call finish in activity B , when calling Activity A from C , call finish() in activity C !
You can use, According to me two ways,
If you start an activity using startActivityForResult, then you can call finish() in this new Activity when you're done with it and it will return control to the activity that started it.
OR otherwise, May be I am wrong,
Call finish inside onStop 'override method'.
make a uniform resultCode for closing child activities. Eg. you make 911 (should be int) as your resultCode. If you want your Activity to finish and go back directly to parent Activity, you set the resultCode to 911:
setResult(911); finish();
In every child activity, you override the onActivityResult and check if the resultCode is 911. If yes, then call the setResult(911); finish(); until you get back to your parent activity. Hope this helps!
For example, if you want to start intentB, you can do following in old activity:
Intent intentB = new Intent();
intentB.setClass(XYZ.this, abc.class);
intentB.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentB);