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.
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
Related
When clicking on the app-shortcut, I am opening an Activity with a Dialog theme. It seems that the app-shortcuts are not closed if I use that theme on the Activity. If I delete the Dialog theme, the app-shortcuts are closed after clicking on one of them.
Any idea? Thanks!
I was able to reproduce your problem, at least with the Pixel Launcher.
The rendering and behavior of app shortcuts is up to the app that is showing the shortcuts. Perhaps the Pixel Launcher is only collapsing the app shortcuts panel in onStop(). When a shortcut launches a full-screen activity, the launcher activity is called with onStop(), and so the app shortcuts panel goes away. But, when a shortcut launches a dialog-themed activity, the launcher activity is not called with onStop() (since it is still visible), and so the app shortcuts panel remains.
Regardless, this behavior will vary by home screen (or other user of app shortcuts), and there is nothing much that you can really do about it.
I'm trying to create an app in Android, using Eclipse ADT and I use a HTC phone. Here's the problem: after running the app on the phone from Eclipse, I add elements to my ListView and everything is fine, BUT when I turn the device in landscape mode the hole app seems like it restart, there's no more records inside. It's like new. Any ideas why and how I can solve this problem? Please don't tell me to deactivate the screen rotate option from phone settings.
This is the way android handles orientation changes. It reloads your whole activity. The normal way to handle this situation is to save the state of your activity in onPause() and then retrieve it back in onCreate().
Here is more information on the android activity lifecycle:
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
EDIT:
You should implement onPause() anyway, because it will also be called if the phone rings in the middle of running your activity. In this case, when the user comes back from the call your activity will possibly be reloaded from scratch again and the user will lose their state.
There is a similar question here.
Basically you application is restarted. You can either force your application to portrait or follow the steps here to find out how to handle it properly.
I made answer over here about this sort of thing.
Please don't tell me to deactivate the screen rotate option from phone settings.
I'm not sure if you meant the following, but here's a solution:
Add android:configChanges="orientation|screenSize" to your <activity tag, which is in your AndroidManifest.xml, like so:
<activity
android:name="activity_name"
android:label="#string/app_name"
android:configChanges="orientation|screenSize" />
This will prevent the activity from being destroyed when the orientation is changed, like it usually would. There are other ways to fix this as well. Please leave a comment if this is not your desired solution. I can make up another.
I have a tabactivity, from it when I start another activity then this activity is getting destroyed.
Now this happens on one device whereas on other its working fine.
If due to bad luck there comes no soln for this, then is there any workaround ?
I am detecting the home activity destroy as an exit from app.
Well it was a rare issue, the device was having too many google account and apps, when reset its working ok. It was a memory issue i think.
I have an app which has an activity A, that lets the user click on a thumbnail and go to another activity B which shows the thumbnail full screen. On activity B, if the user clicks anywhere on the screen, it closes the activity.
Both activities are defined as portrait in the manifest, and both have the onConfigChange value to contain the orientation flag.
It works perfectly on all versions of Android and all devices that I've tested, except one - Motorola Xoom, with Android 3.1. On the Xoom, if the user navigates quickly between the activities (back and forth), it has a chance to show activity A in landscape mode for a very short time, as if it planned to switch to it.
Not only that, but if it remove the flag of the onConfigChange in the manifest, activity A might re-create itself from scratch on this special case.
What could cause this weird thing? Is it some weird bug on android 3.1 or the Xoom? Is there anyway i can fix this issue? I could have something that blocks the touch on activity B for a few ms on the beginning, but that's just a workaround.
While testing on Android 1.6 using a G1 I have noticed that when I slide out the keyboard it kills the activity and recreates it even though I have set my activity to only display in portrait mode.
Same happens when I push the keyboard back in.
I get onSaveInstance, onDestroy called, then onCreate, onResume, OnrestoreInstance...
I understand why this is done when the display is being switched to landscape view but why does this happen when I specifically dont want my activity to switch view, its essentially killing and restarting the activity for no reason.
Is it the same on 2.x devices?
Is there something I'm missing to stop it happening?
Can anyone explain if there is any point to it?
This is the recommended behavior in Android. But if you want to stop this you can specify the following property in your Manifest against your Activity
android:configChanges="keyboardHidden|orientation"