FLAG_ACTIVITY_NO_HISTORY is not working for starting android settings activity (android.provider.Settings.ACTION_SETTINGS)
I have an activity from which I start Android Settings Window (android.provider.Settings.ACTION_SETTINGS). I do it like that:
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
activityContext.startActivity(intent);
It usually works. However, when I follow these steps:
1) launch settings from my activity
2) go further (i.e. Wireless & networks),
3) press home, etc
3) launch my activity again
4) launch settings from my activity
5) then 'Wireless & networks' screen appears instead of main android settings activity!
I also tried:
Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activityContext.startActivity(intent);
But it's not working either. Do you know what might be the problem? I wanted to add that flag FLAG_ACTIVITY_NO_HISTORY works for my internal activities.
Try adding the flag Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED to the intent.
Related
Is there any way to, in my app, to redirect a user to a specific settings 'page'? My app works as a lock screen app, so I want to be able to redirect the user directly to the "Lock Screen" section of the Android settings. (Preferably via a button or something similar)
ACTION_SECURITY_SETTINGS Intent:
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);
For complete Settings Intents
I managed to find the correct answer in an old Stackoverflow-post from a while back. The code snippet now looks like this:
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
val intent = Intent(Settings.ACTION_SECURITY_SETTINGS)
intent.flags =
Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity(intent)
Note the flags. These are optional, but necessary to remove the previous settings screen from the screen if it was previously open (this is needed if your application wants to open multiple settings screens).
My application has two activities A and B. A is the root of the task, and is the one that is launched from the launch icon. B can be started from A.
As well as starting A from the launch icon, it is possible to launch A by clicking on a file in another application, e.g. clicking on an email attachment or a file in Drive. I have done this by adding actions and categories to the intent filter in the manifest file.
I want to make it so that when A is launched from another application, instead of creating a new task I want the existing task to resume in the same state it was in before. This could be activity A or B, wherever the user happened to be before they pressed home.
I have tried all kinds of launch modes and intent flags but nothing seems to work.
Broadcast an intent that's identical to the launcher intent in your manifest:
Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
I don't know why, but this raises the existing task instead of starting a new one. By contrast, a launcher intent obtained the "official" way will actually start a new task:
Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(context.getPackageName());
change launchmode to singletask. and listening onNewIntent()
When user press "Home Button" my app go to Background, but is still running. I need bring my app to front again. For example i've this code:
Context ctx=getApplicationContext();
Intent i =ctx.getPackageManager().getLaunchIntentForPackage("com.example.test");
ctx.startActivity(i);
but this code is to open app in different activity, there are a method or something to do this "correctly"?
You can simulate the "launching" of the app the same way that Android launches the app when the user selects it from the list of available apps. If the user starts an application that is already running, Android just brings the existing task to the foreground (which is what you want). Do it like this:
Intent intent = new Intent(context, SplashScreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You need this if starting
// the activity from a service
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
(Source: https://stackoverflow.com/a/12075313/3529926)
You can set this flag to your intent
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
and set the launch mode of your activity to single task in manifest (add this is your activity tags):
android:launchMode="singleTask"
Hi I am stuck with this issue.
I have my app which has 3 activities:
SplashScreenActivity, LoginScreenActivity, ViewPagerActivity(which houses 3 fragments).
When I put the apk in the mobile sdcard and install and open using the packagemanager. My App starts up just fine.
Issue - But, now if I press the Home Button and again launch the app from the Apps drawer/Homescreen. The App seems to relaunch and I have to go through the entire flow of Splash and LoginScreen.
This issue does not occur if I launch the App the first time itself from the Apps drawer itself./If I long press the Home Button and select the App from recent apps list the app is resumed properly as well.
For Reference I launch activities using these flags
Splash->Login
Intent intent=new Intent(SplashScreen.this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
LoginActivity->ViewPagerActivity
Intent intent = new Intent(context, ViewPagerActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Home screen icon launches whatever activity you have declared as the MAIN ... LAUNCHER activity in your manifest. Generally, the launch activity in manifest should be the main activity of your app. From there you can invoke splash screens and login activities when needed.
remove these flags or the complete line of code
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
This seems to be an issue when launching with package manager.
https://code.google.com/p/android/issues/detail?id=2373
if (!isTaskRoot()) {
Intent intent = getIntent();
String action = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && action != null && action.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
Hello i am new to android.I am implementing some application and it have some activities.
Suppose if i launch the app for first time,it's entering in to A then going to B after that C,D,E..... (Here A,B,C,D,E are activities).If i press back button at E then it is going D--> C--> B--> A like this.
Now i want to implement code to exit/quit from the app when i am at D.
I wrote following code but this code is working for closing current activity and going to prev activity.means going C.
finish();
Then i tried with following code and it is working fine and closing current application successfully and going to device home screen.But if i want open the application again then it is starting form D instead of A.
intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
copied from here
Please help me to solve my problem.
Use these flags to lunch the activity and clear the activity stack
Intent intent = new Intent(this, YourActivityD.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Be aware that FLAG_ACTIVITY_CLEAR_TASK is only available from API 11
See: http://developer.android.com/guide/components/tasks-and-back-stack.html
Try this:
finish();
System.exit(0);