Re-launch app on application launcher icon tap - android

According to Android behavior when user takes an app to background by pressing home button, on launcher icon tap the app will resume from where it went to background. I want a different behavior in my app, i want to relaunch the launcher activity whenever user taps on the launcher icon, no matter the app is in background or not.
Any suggestions?

just set this in your launcher activity
android:clearTaskOnLaunch="true"

Related

Launch service on home button press

Android M:
I am trying create/resume a service whenever the home button is pressed. The activity that is displayed when the home button is pressed should not be destroyed/paused. I have tried to make my service filter the android.intent.category.HOME intent but android does not seem to recognize this as a launcher. Is there any workaround to solve this problem?
I am trying create/resume a service whenever the home button is pressed.
Implement a home screen. Convince users to use your home screen. Tie your service into your home screen implementation.
The activity that is displayed when the home button is pressed should not be destroyed/paused
The activity that is displayed will be paused, because the HOME button always brings another activity to the foreground. The only exception is if the home screen is already in the foreground. There is nothing that you can do about this, other than write your own mobile OS.
The activity that is displayed will be destroyed if and when Android decides to terminate the process associated with that activity. You do not get a vote.
I have tried to make my service filter the android.intent.category.HOME intent but android does not seem to recognize this as a launcher.
That is because the HOME button will start an activity, not a service.
So there is no way of implementing your own launcher that does not open the Home screen?
You are welcome to implement your own customized version of Android that offers this. Then, you can put that version of Android in your own custom ROM, then convince people to use that ROM.

Checking if the app was resumed from recent apps or from the launcher icon

I would like the distinguish the event where a user resumes my app from the "recent apps" list, or from the launcher icon again even if there is an unfinished app running in the background.
My app is a single Activity containing multiple Fragments, the intended behavior is that if the user resumes from "recent apps", I wouldn't have to do anything as the default behavior brings them back to the fragment they left it at. However, when the user launches the app from the icon again, I want to pop all the fragments in my fragment manager to the first fragment, essentially behaving as if starting the app fresh.
Right now though, even if the user taps on the launcher icon, the app will be resumed as usual like from the "recent apps" list without onCreate() being called on the Activity.
I've looked at similar questions, but they seem to indicate that the activity DOES get recreated when the user launches from the icon again, which is weird and not what I observe: Android resume app from recent applications list
Any ideas?
You can try adding this attribute to your manifest file for your activity.
<activity>
...
android:launchMode="singleTask"
</activity

Control Launcher option in android

I have created an app for visually impaired. When the user clicks on Physical Home button I am getting the launcher dialog box working perfectly fine.
Instead of inbuilt dialog box. I would like to get my activity screen which has the list of launchers so that user can select and open any launcher according the requirement.
For e.g.
If the user has two launcher
Launcher (Default)
MyApp launcher
On myactivity screen it should show up launcher and myApp and user should able select anything required.
Is this possible? if so how? Can somebody direct me to that page as a start?
Thanks!
When the user presses the home button, the system is attempting to fulfil the android.intent.category.HOME intent. The dialog pop up is there when there is no user preference, the system will always have control of this UI.
What you could do is fulfil this intent yourself, and be the default launcher - even if your launcher's action is to provide the means to launch another launcher?

Home screen component name

I am developing simple home screen application. So when i press home button i can
choose between native and mine home screen app. The problem is: if i set my app as default
home screen application when i restart phone i can't enter native home screen app
because it has never started so my app stands on top off stack. How can i enter
native home screen app when i restart phone if mine is default home screen app?
I have idea:
On boot, i can check the calling intent - if it contains the Home category, i will call native home screen app. Something like this:
Intent creatingIntent = getIntent();
if (creatingIntent.hasCategory(Intent.CATEGORY_HOME))
{
creatingIntent.setPackage("com.android.launcher");
creatingIntent.setComponent(new ComponentName
("com.android.launcher",
"com.android.launcher2.Launcher"));
startActivity(creatingIntent);
finish();
}
But the problem is i don't know how can i get Component name for native home screen application, can someone help?
The goal of an home app (=launcher) is to replace the native launcher, it's weird to force the cohabitation of 2 launchers. But if you success to do something like that, when you press on the home button it will launch also the Native launcher.
To answer your question, the native launcher depends of the target device. Example : samsung doesn't use the same launcher than google, so components name will be different.
Have you tried to do a broadcast receiver which launch your app at start up ? With that, you don't have to put your apps as default home app, so you conserve the choice when you press on the Home button. However, it's not a solution if a user choose your app as default app.
Maybe you can look here How to use customized screen instead of default start screen in Android?

Reset default launcher when app is closed

I have created a children's app that has a child lock using a custom launcher, however I have one small problem. When the app is closed and the home button is pressed the dialog to select the default launcher is displayed. Is there are way to reset the default launcher when the app is closed?
You cannot make any particular app be the default. However, you could use PackageManager and setComponentEnabledSetting(), to disable your activity that has the HOME category. Re-enable that when the user wants to have the choice of using your home screen again.

Categories

Resources