I am working on a launcher application. It is being show along with the default launcher on pressing the back button. However, wherever I am in my custom launcher or whether in the starting page of my launcher it self, when I press the back button, the screen navigates back to the default android launcher. I need help.
This is the code I used to set my app as a launcher
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
thank you in advance
This seemed to work for me
Kotlin
override fun onBackPressed() {}
Java
#Override
public void onBackPressed() {}
Those are categories for intents, android.intent.category.LAUNCHER just means when you run the application it will launch the specified class
Related
I want my app to handle the HOME key press with a custom action, and also stay in the foreground. I put the following code in AndroidManidest.xml:
<activity
...
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
....
</intent-filter>
</activity>
However, this has set my app as the new home screen, which I don't want. I only want to capture the key press while my app is in the foreground, just like you can capture other buttons. Is there any way to do that? Perhaps set the intent filter to only work while my app is in the foreground?
I am using Branch IO in my application and as per their documentation, I am using android:launchMode="singleTask" for my activity.
Here is some code snippet of my AndroidManifest.
<activity
android:name=".SplashScreen"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data
android:host="open"
android:scheme="com.package.name" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App Links (optional) -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="app.link"
android:scheme="https" />
<!-- <data android:scheme="https" android:host="example-alternate.app.link" /> -->
</intent-filter>
</activity>
Everything is working fine except when I press Home button while using app and tap on App/Launcher Icon, onCreate method of Splash screen activity is called which makes it looks like app is launched from beginning. However, if I press home button while using an app and open it from recent apps, onCreate is not called and everything works perfectly.
How do I make consistent app behavior when brought to foreground from recent apps and App/Launcher icon?
I tried removing singleTask launch mode which makes launch perfect from App/Launcher icon and recent apps but when tapped on branch IO link, the new instance of an app is created. I can understand that to overcome this problem only they are asking to put singleTask in launch mode.
I have checked for this scenario in many apps which are using deep links and they do not have this problem!
I must be doing something wrong which I cannot see.
Is something is missing or implementation is wrong?
Solution to this problem is moving to Single activity architecture.
As splash activity is singleTask, onStart method of it will be called each time when the app is brought to foreground from launcher icon. One has to write routing logic in onStart method, when another activity is started from here, app state will lose.
If a single activity is there, this problem will not be there. However one will have to deal with nasty fragment backstacks. Not an easy but correct approach.
For a quick workaround, one can use this code in onCreate method of activity with launchmode as singleTask.
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
return;
}
This might help to avoid unnessary execution of code written in onCreate. However this is a recommended solution as it doesn't solve rootcause of problem.
I've written a custom Launcher and it works pretty nice. The Launcher has some pages filled with applications. I want to implement, that the variable that represents the page number is set to 0, if the homebutton is pressed. So if you are on a different page of the launcher and press the homebutton, you enter the starting page.
I've searched a lot, but couldn't find an answer that worked for me.
I've set the app as an launcher in the manifest.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Is it possible to achieve this? Just change the value of one variable, if the home button is pressed and leave the rest of the home button, as it is.
For everybody who want to do the same thing. that's the way i solved it:
I added the following to the manifest:
<activity
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true">
and wrote this into the java activity:
#Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (Intent.ACTION_MAIN.equals(intent.getAction())) {
final boolean alreadyOnHome =
((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
!= Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
if (alreadyOnHome) {
Log.d("whatever", "Home pressed");
}
}
}
I got it from here: CyanogenMod trebuchet
I do not know if you get my question right, so let me explain:
My app is shown in the chooser after user clicks a web link in any other app, then user clicks on my app and my app shows the link in a webview. This works fine.
But, the problem is when the user launches the other app again (which invoked my app earlier) with a click on the icon that is on the home screen or app drawer, it opens my app again instead of the origin app.
Manifest:
<activity
android:name="com.droidfox.app.browser"
android:label="#string/browser"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
</activity>
Back Button Override:
#Override
public void onBackPressed ()
{
moveTaskToBack(true);
}
Does anyone have a clue why the other app launches my app and how can I fix this?
Try to set android:noHistory for your given activity.
Taken from documentation:
Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. The default value is "false".
A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.
I had an android launcher project. After installed on my phone, pressing HOME will NOT make the "default launcher choise" popwindow showing to choose default launcher.
following is related setting:
<activity
android:name="MyLauncherActivity"
.....
.....
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
how can I make that popupWindow show ?
P.S How curiouse it is! I just restart Eclipse and reinstall it, pressing HOME make the default launcher choise popupwindow showing!
<category android:name="android.intent.category.LAUNCHER" />
in your activity intent-filter means this is the start point of the app, when the user clicks on the app icon, will run this activity ( it doesn't mean this activity is a launcher app)
and you are looking for this:
How to make a launcher