5

Sometimes, most of the time when my LG G watch closes the app automatically by going to sleep/dim mode, if I open the app again by going to the start menu there are two instances of the activity opened (when I slide one off the previous one is underneath).

This never happens in a phone, is this how activities work in Android Wear? Should I "finish()" them in onPause()?

Thanks.

1 Answer 1

3

Have you looked at the android:launchMode attribute in the AndroidManifest.xml for the activity?

perhaps android:launchMode="singleInstance" will help you out.

http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

8
  • 1
    This seems to have done the trick, thanks. One thing to note though is that if you launch the activity from Android studio upon uploading the app and then you close the app and try to open it again this second time you won't be able to open it and the screen will turn black (I'll have to do more testing to find out why this happens before I release my app). My guess is that the ADB launch is somehow different than the standard "start" menu launch. Aug 15, 2014 at 4:32
  • Be aware that if youre using an intent to pass the app data, youll need to look into onNewIntent(Intent i)
    – r2DoesInc
    Aug 15, 2014 at 11:15
  • I am running into the same problem, very annoying.
    – Nick H
    Aug 1, 2015 at 18:22
  • @SoftwareDev It's been a long time, but did you learn anything about why this happens?
    – akodiakson
    Oct 18, 2016 at 14:19
  • @akodiakson I'm don't remember exactly, but looking at my commit history for the app in github which is titled "Fixed issue that caused activity to open more than once." what I did is added the FLAG_ACTIVITY_NEW_TASK to a notify intent I had, this is code I used: notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); In the same commit I removed android:launchMode="singleInstance" from the code, so that must not have been the real solution after all. Best of luck, and let me you know what you find out because I'd like to remember why that worked. Oct 19, 2016 at 4:44

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.