I'm not sure if this is expected, if it's a bug and whether or not there's a workaround.
When a user hits the home button in our Android Phonegap app, the application minimizes properly.
When the user clicks the icon to launch the app, it restarts from the beginning. This is undesirable.
After a user minimizes the app by clicking the home button, there are two ways the app will resume properly:
A long press on the home button and clicking the app will resume the app in its last state.
Clicking a notification in the status bar (push notification) will resume the app in its last state.
So my question is, what do we need to do to resume the app in the same way those above two items do when the user clicks on the app icon from the desktop? The app is running and healthy as item 1 listed above confirms.
Any help would be greatly appreciated. Thanks!
I had the same problem . My app was getting restarted when i click the app icon to relaunch the already running app in the background.
Basically if the android:launchMode is set to standard or not set ,then a new intent is created for the app and the old paused state of app is not resumed .
So the best way around i found was to apply
android:launchMode="singleTask"
in the AndroidManifest.xml -> inside <activity> .
please conside this example :
<activity android:name="Example" android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Related
I'm facing the following issue. I have an app with an established user base, and I wanted to change my default launcher activity for the app.
The problem happens only for some users that updated the app via Google Play. Problem does not occur when running via Android Studio.
The problem comes into play with some of the users' Launchers on their phones. After they update the app, and when they try to open the app from their homescreens some users get "Error app not installed" or "Activity does not exist" errors.
It seems that on some users' devices, the OS launcher adds additional information about the activity name and this causes an issue after they update the app.
What's the correct way to change the launcher activity in order to avoid the problem I described above? This is quite an issue as a lot of non-techy users just uninstall the app.
Previously .TabHostActivity was set as Launcher/Main
After making .SplashActivity as Launcher/Main and rolling out the update to Google Play, some users started receiving "App not installed" error when opening the shortcut from their homescreen. App still works if they open it via App Drawer, but the shortcut on the homescreen gives this error.
Code:
<activity android:name=".SplashActivity" android:screenOrientation="portrait" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TabHostActivity" android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
Make TabHostActivity Launcher activity again.
In TabHostActivity at first check if it has been opened from SplashActivity (You can add a flag in the intent while starting the TabHostActivity from SplashActivity and check the same flag in TabHostActivity)
If TabHostActivity has not been opened from SplashActivity, then redirect to SplashActivity.
All of the above should be coded before any other code in OnCreate of TabHostActivity.
I'm using Mosync SDK 3.2.1 to develop a HTML 5 application for Android 2.2, 2.3 and 4.03. I had the issue described in this post http://jira.mosync.com/browse/MOSYNC-2367 . The fix proposed
android:launchMode="singleTask"
solved the "restarting of the app" issue when launching the app from menu but broke the launching behavior of the app via notifications when the app is working in background. (in launchMode="standard", works fine, the app resumes). With this fix it crashes with the message "Unfortunately, Zymbo has stopped" (4.0.3) and "The application Zybmbo has stopped unexpectedly."
If the application is not working in background the launch via notification works fine, the app is started.
This is how the MAIN activity is declared in manifest file.
<activity android:name=".MoSync"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This is how the application behaves right now:
1. Launch the application via menu shortcut
2. Press "Home"
3. Launch the application via menu shortcut (launchMode="standard" => restarts the app BAD / launchMode="singleTask" resumes the background app OK)
4. Press "Home"
5. Launch the application via notification item (launchMode="standard" - opens the app working in background OK / launchMode="singleTask" the app crashes BAD)
What I want to achieve is if the application is running in background and I click the notification or the app icon from menu, i want the application to resume and not to start again.
Any hint is appreciated, Thank you,
Mike
I'm developing an android application for my customer. And in that, the User needs to work with that application only. The User should not use any other applications in the Tablet, and my application need to be the default application after i installed the application...
If i shutdown the Tablet my application will be stoped, and if i switch on the tablet means my application will be automatically started.
could i achieve this, any steps to achieve for it..
Help me to fix this, Thanks in Advance
you can start your application while boot is completed using broadcaste but you cant stop the app getting exit while user pressed home button.
You may define your activity as Home, in the manifest file, define as below:
<activity android:name=".YouClassName">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This way, after install you application, when user long tap the Home button, Android would prompt use to choose which HOME to enter, one is the system default, the other is your activity. At this time, user may also set your activity as default HOME, then when power on, system enter your activity automatically.
If you permission to delete system default launcher (the default home), then your activity becomes to be the unique home.
I made an exceedingly simple app consisting of a launch activity (.TestActivity) with nothing more than a button on it, and a 2nd activity (.second) with nothing more than a piece of text on it.
Then I create an .apk file from it and sideload it to my phone, I open the app, click the button and go to the 2nd activity, press Home to make the app leave the screen, and then press the icon of the app to open it again, it resumes on my FIRST activity and not the 2nd one that I would expect.
After I force close the app it works properly, though! Where is the problem here? It's not my phone because I've seen this on several other devices that I've tested with. It's not necessarily Eclipse because it works as expected on Eclipse (and the emulator), it's possibly the manner in which I package the .apk file (but even then it's a pretty standard "export" that I'm doing from Eclipse so I'm not sure what that would be). Any other ideas?
Here's the manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".TestActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/app_name"
android:name=".second" >
</activity>
</application>
Why would force closing the app make it work how I want it to work the 2nd time, though?
Here's the deal. In your Android Manifest you identify which Activity you want to load when launching your app. If, for some reason, your app is not resident in the task stack Android will launch that Activity. If your app is in the task stack Android may choose to bring it to the front and you could be looking at whatever Activity was showing when you left the app. The thing is you cannot count on this. If you want the first Activity to show only te very first time the user launches your app you need to set a flag and then on subsequent launches you can automatically launch the second Activity based on that flag.
I just found the following links:
http://code.google.com/p/android/issues/detail?id=26658
and a decent workaround here: Home key press behaviour
I understand what CaseyB is getting at, but I can reproduce this every single time. If my app has a memory leak or ends up getting killed due to inactivity or the need for Android to reclaim some of its resources, that's one thing. But this seems pretty obviously like a bug to me and I'm just going to have to live with the workaround for now.
Edit / Update:
As an update to the below problem, I found the exact action which causes it to happen.
Download an apk from a url through the android browser
Install the app.
After install, the app gives you two choices: "Open" or "Done".
If you choose "Open", the quirky behavior described below starts.
If you choose "Done", then launch the app from the app tray, it works fine.
So it seems like this problem is caused by using the "Open" button the browser provides you after installing the APK.
I'm experiencing an error in the history stack of applications upon first install. I made a test app to demonstrate this.
The test app is simply two activities, A and B. Activity A launches B. That's all it does. Rest is wizard generated template code from eclipse.
When the user installs the app (via web url apk), and runs it for the first time, I get an out-of-order activity stack:
User starts the app, A is on top.
They make A launch B by clicking a button. B is on top of the stack.
User hits the home screen button.
User returns to the app, A is displayed, instead of B.
User hits the back key, B is shown!
User hits the back key again, A is shown!
User hits the back key again, home screen shown.
Now the stack is clean, and app behaves "normally" from now on!
Is any one else seeing this? This is almost exactly like this known bug, however my users are not installing from eclipse:
link.
I can provide the test app/source if anyone wants to try. This is the manifest, which does not have any special customizations made to it.
<activity android:name=".ActivityA"
android:label="ActivityA">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ActivityB"
android:label="ActivityB">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
As far as I know, this should definitely not be happening, and works fine after you clear the history stack the first time.
Thanks