I have an app that shows the user a profile edit screen the first time he or she uses the app. Within the edit profile activity, I need to allow the user to create a profile image capture an image or select from the gallery.
I want to be able to catch OnActivityResult, but once they are done with
editing profile, I don't want this to be on the stack. Setting noHistory to true kills the activity and I can't catch the result.
I want this for first time:
splash screen----> edit profile ----> main menu.
When the user presses the back button from the main menu, I want the app to stop, not pop edit profile from the stack.
Any idea on how to set noHistory after I've gotten OnActivityResult?
According to the documentation there is no way to get result in activity that is specified with "noHistory"
In this case, onActivityResult() is never called if you start another
activity for a result from this activity.
You can try to achieve desire result by clearing existing stack like this:
Intent i = new Intent(context, MainMenuActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
It should start new task based on main menu activity.
Related
I want to always start launcher activity after app goes to the background. I tried android:clearTaskOnLaunch="true" but it not work. How can i do this? For example i have A,B,C,D,E,F activity. A is launcher activity.
now i open app so A activity is called then A>B>C. now i minimize the application. Now i open application from the icon so app is start from C but i want it start from A so how can i do this? some said use onResume intent with Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK. but what if i press back button then onResume is called and my app start with A activity.... so it is not work..any solutions???
You can check the App is in foreground or is in background and when the application goes to the background state at the same time do some logic that when your application comes to foreground it will always show the root activity.
How you can identify application is in which state is well explained here
When you start Activity B, use these flags. That way Activity B and C will always be in a separate stack. That means that when someone starts Activity A from the home screen they will see Activity A always.
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
Intent intent = new Intent(context, B.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(intent);
Also this might help, you can add this flag to your root Activity.
<activity
android:name=".ui.MainActivity"
android:clearTaskOnLaunch="true"/>
This does because device store data about application. For short time data are stored. if you want to start application from rot class. use service with application, so that whenever your application goes in background and pause then choose your action to do that will be easier.
I need to clear the back history of activities.
I have 5 Activities.
In the first 4 activities I have to make the back button go to and fro with data filled in all the screens. But as I proceed on 5th screen I need to reset the back history and start intent with new stack. So that after i press back in my 5th screen app should exit. I tried using launchMode , Nohistory and Flags such as NEW_TASK , CLEAR_TOP, CLEAR_TASK but still unable to achieve this. Please help me. Suggest me how to achieve this.
In your comments you suggested that you've tried using flags like:
Intent i = new Intent(MainActivity.this,SecondActivity.Class);
i.addFlags(android.flags.FLAG_CLEAR_TOP | FLAG_NEW_TASK | FLAG_CLEAR_TASK)
But instead try using them like:
Intent intent = new Intent(MainActivity.this,SecondActivity.Class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
Right now, what is happening is when I press home-key, last active activity is displayed. But what I want is to start the application as new every time the user presses home key and start the app from launcher. Please help
I think you can override onPause() event when you pressing home button and in there you can implement finishing your activity.
with setting intent flag as FLAG_ACTIVITY_CLEAR_TOP on starting your Activity your back stack would be clear so with finishing the last activity there is no activity on the task and stack
While creating intent you can set the flag. for example
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
I have an app widget on the home screen which includes a button that launches a basic settings Activity.
When the user presses the Back button, if the main application has some activities in it's stack, the back press takes you to the most recently viewed Activity in the app, rather than back to the homepage. I've tried the following flags for my intent:
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
But no luck with any. Is there any flag or combination of flags I can use to do this? Thanks.
You need to do the following:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
You are currently using setFlags which overrides the flags you set previously when you need both of these flags for it to work correctly.
You can read abut this at http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP
try next
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
This flags run activity in new task and don't add it to history after exit.
So your settings activity don't cross with main app
I am developing an application in android. I am new in android.
In my application I have a category selection activity from that user have to check a check-box, based on that he will get view on another screen. I have a menu button in 3rd screen in that I have a button for selecting category, when I click on that button its also works fine but when I click back button it will redirect me 2 times at same activity... How to remove this problem? I have used finish() method but its also creates problem its get's me out from the application directly...
I want redirect to selection activity and it should not show me 2 times when I click back button ....
Is there any way please redirect me thank you.
a call to finish() should work so you schould check your code for multiple calling the wrong method or something like this.
Intent intent = new Intent(activity, activityClass.class);
activity.startActivity(intent);
finish();
you should also take a look at the Intent flags:
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
Your question isn't clear enough for me to know if this will solve your problem, but if you include the following attributes on your Activity in AndroidManifest.xml, the so-attributed Activity will never appear in your history list.
android:excludeFromRecents="true"
android:noHistory="true"
As for removing something from the history, I'm not sure how to do that, but I'm interested in the answer!
You should call finish before you call Intent and go to next activity. so the current task is finished and will not be saved in stack and then you intent activity will come on top of stack. If you directly want to go to Selection activity, override onBackPressed() and intent to the activity you want to go to.
There are different flags that you can use to control how your activity interacts with the activity history stack. Two that might be of interest to you are FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_NO_HISTORY.