Weird Home button behavior

I'm experiencing kind of strange behavior of my application after hard Home button is pressed. When you press Home, everything is OK - my app goes to the background, showing Home screen. But if you try to choose my app in the main menu or in the list of last tasks it behaves like it was not started before and does not show the last activity you were on - it just starts from scratch, namely, shows the splash screen and starts next corresponding activities. Moreover, old activities of this app remain on the activities stack, and previous instance of the app is not terminated - so if you press Back for a few times you'll just run into those activities which were undoubtedly started during the previous session of work with my app. Splash screen activity is filtered by "android.intent.action.MAIN" filter and "android.intent.category.LAUNCHER" category. The strange thing is that all of that happens despite the fact that I do not intercept any Back key hits, or override any onPause or onResume methods. What's happening contradicts with my understanding of Android app lifecycle - I was sure that when you hit Home an app just goes to the background, and when you choose it in the menu later - it just unwinds and does not start anew. (Of course, unless stuff like that is stated in the app manifest or corresponding methods are overridden or something else). I also checked it for some other lifecycle events - such as changing orientation or flipping hard keyboard out - and none of those led to such strange results. It appears that the problem occurs when you try to start the app from main menu or menu of last applications. I hope you will be able to help me. Any advice on what to pay attention to or where to search for solution would be really great.

Regards, Alex


Asked by: Daniel907 | Posted: 20-01-2022






Answer 1

You need to set android:launchMode="singleTask" in your LAUNCHER activity in your manifest file.

For more info on the launchMode attribute see here

Note that:

The default mode is "standard".

and:

Every time there's new intent for a "standard" activity, a new instance of the class is created to respond to that intent.

Answered by: William206 | Posted: 21-02-2022



Similar questions

java - Weird behavior in Android's "if" block

It walks like a bug, it chirps like a bug.... I need someone to confirm that it's a bug. I was trying to get phone numbers from the address book with this code: public JSONObject getAllPhones() throws JSONException{ String mPhoneNumberProjection[] = new String[] { Contacts.Phones.NAME, Contacts.Phones.NUMBER, Contacts.Phones.TYPE }; Uri phoneNumbersUri = Contacts.Phones.CONTENT_URI; JSONObj...


Weird shadow behavior for android MapView

I am putting several markers on a MapView by subclassing an ItemizedOverlay. The hitch is that the marker I am passing to the ItemizedOverlay is a custom Drawable. That is to say, I've subclassed "Drawable" and I have overwritten the draw() method. The point of this was to add a color filter to the Drawable, and add custom text: public void draw(Canvas canvas) { String[] colorComps = color.split(",")...


Android SMS Sending behavior

I 've developed on SMS sending application for Android devices. A pop up opens up asking to choose sms applications (native app or mine ), whenever I try to send SMS to contact already present in Contact Book on my android device. But in case, if I try to resend a SMS already present in sms box in android device, no such pop up opens up ?


android - How do I set the behavior for an inflated view?

I have an audio player toolbar activity that has a corresponding layout file. I need this player to show up at the bottom of another activity. I use a ViewStub and inflate the audio toolbar's layout file in the stub. How do I access the buttons, etc on this inflated view and how do I set their behavior? The docs on ViewStub did not mention anything about this (or maybe I totally overlooked something...


input - Android Long Press on Edit Text behavior

Is it possible to add something to the list of items that shows up when a user long presses on any Edit Text? (Cut, copy paste, select text, select all, input method) I want to add an option to this that will scan a QR code and paste the result into the Edit Text. I think this would not be very hard to get this behavior out of Edit Texts that I put into my own application, but I am wanting to add this option to any Edit Te...


Weird list behavior in android

I have an ImageView on top of a ListView and whenever there is a long running process to populate the list I would like to hide the ListView and make the ImageView visible. I tried some things with setVisibility() but I'm getting messed up scroll behavior for the list. I'm using AsyncTask to manage all this but I don't think that...


android - How to change behavior regarding "Cannot play video" error

I am trying to play a video via HTTP. It sometimes plays fine, others I get the "Cannot play video" error but can immediately start playing it again. It seems it will display this error on the slightest hiccup, is there anyway to increse the tolerance so it can continue through instead of just dropping the download and popping up the error?


android - Different state storage behavior for "Back" vs "Home"

I am still learning the ins and outs of Android development. I am playing around with the Notepad tutorial application to try and get different behavior. Right now, I want to have the application do the following in the NoteEdit activity: 1) If the Back button is pressed, current state is ignored; basically, it's like an implicit cancel, and you are taken back to the list. 2) If the Home button is ...


android - Weird camera Intent behavior

I'm invoking the MediaStore.ACTION_IMAGE_CAPTURE intent with the MediaStore.EXTRA_OUTPUT extra so that it does save the image to that file. On the onActivityResult I can check that the image is being saved in the intended file, which is correct. The weird thing is that anyhow, the image is also saved in a file named something like "/sdcard/Pictures/Camera/1298041488657.jpg" (epoch time in which the image was taken)...


c# - Unusual behavior of text inputs on stock Android browser

Edit: Tested on Droid X running Android version 2.2.1. Samsung Galaxy S version unknown. I'm developing a webpage designed to run on mobile devices, specifically Android and iOS. Everything seems to be working fine on iOS, but I'm experiencing very weird behavior on Android. I'm using ASP.NET with C# and jQuery. Specifically, I have a form with several text inputs....






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top