Two instances of my android application are running…How to avoid this?

I will bet money you are not saving anything OnPause, and starting a new instance all the time via OnCreate You should read the notes on Activity Lifecycles.

I will bet money you are not saving anything OnPause, and starting a new instance all the time via OnCreate. You should read the notes on Activity Lifecycles.

I can't recommend reading and re-reading that link for new Android developers. You need to study it. – sgarman May 7 at 3:53 The above described scenario of two application instances will not occur if I directly run my application in Eclipse with USB connected to device.In this case my application automatically get launched.

I don't need to copy . Apk file to memory card and manually install it. – Waugh May 7 at 3:59 do you see two separate activities when you go into the Task Manager?

You might be seeing two different activities because you are installing both a debug apk AND the release apk. You can then have 2 variations of the same activity. – Dr.J May 7 at 4:30 post code please – Dr.J May 7 at 4:30.

I believe you need to put in the manifest file.

Android does not run the same application multiple times , It is just restarting your application for some reason instead of resuming it. Have you by any chance set the nostory flag in your activities?

If you haven't got this sorted yet, I would say your app is actually being killed when home is pressed, or perhaps you have a bug that doesn't latch onto whatever object is keeping state.

I'd like to join initial Waugh's question. It is very easy to reproduce: Create an empty Android project in Eclipse, for example. Compile the project Put APK onto your sd-card Install APK on your phone (don't use adb, select APK in some file manager) When installation completed, select Open - your application will be opened Press Home button Launch your application from Launcher - your application will be opened Press Back button - application's activity will be closed, but another one pops up from a stack.It is what Waugh means under words "Two instances of my android application are running".

So, how to avoid such situation? Pay attention, that t is reproduced ONLY when you launch your application from Package Manager right after installation.

Long-running code, to avoid blocking the main UI thread. Application, use Intent.putExtras(). Preferences storage mechanism.

Components run in the same process through the use of a singleton.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions