2

I made myself an app: a music player with automatic bookmarking :)

Problem:

If I go "back" to the home page and then try to run the app again, it creates a new instance whereas I want to continue. I might leave music running while I do other things and then I can't pause it or save it because I can't access it!

Failed Solutions:

I've tried singleTop, singleTask, singleInstance and they all don't work!

I can view running apps (Settings > Applications > Manage Applications > Running) but it only let's you "Force stop" them. How about "Bring to front"?! Also, when I finish() my app, I notice it's still "running"!

This site is very awesome and useful and this is my first question :) I looked for answers but couldn't find any that worked :(

Here's the manifest:

<application android:icon="@drawable/icon"
android:label="@string/app_name">

<activity android:name="Fire"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:launchMode="singleTop">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
karnok
  • 1,202
  • 1
  • 12
  • 17

1 Answers1

3

Back by default closes the activity. You can override this behaviour by catching BACK key, but in your case, you really need Service not activity to play music and control it. Activity is ment to be destroyed when you leave it on BACK really....

Read more here: http://developer.android.com/guide/topics/fundamentals/services.html

Jarek Potiuk
  • 19,317
  • 2
  • 60
  • 61
  • So you can't have an app running while you do other stuff? And yet apps just keep running unless you violently force stop them?! – karnok Jul 03 '11 at 11:23
  • Thanks a lot though, I found it resumes fine if I click HOME rather than BACK :D I had no idea BACK "kills" it - more like hides it. – karnok Jul 03 '11 at 11:25
  • That's it - it's about the activity, not the application. Activity is pretty much tied to what you see on screen and pressing BACK is a signal "I want to to get out of the activity", where HOME is (I want to switch to something else... It might be a bit confusing, but that's how it is.... – Jarek Potiuk Jul 03 '11 at 11:30
  • Unless it has a service running, or some background threads, or Content Provider, or Broadcast Receiver, or expecting other Apps to sent intent to it and bring it back quickly. Activity is just one small part of Android components really. And such application which does not have any of these extra elements and Activity is invisible is the first candidate to kill by the system whnever it needs memory for others. That's how Android manages running applications. – Jarek Potiuk Jul 03 '11 at 13:56
  • My favourite part is how it keeps "closed" apps running for kicks and giggles until it runs out of memory. **THEN** it closes them. Honestly... But thanks for the info, it does make some sense. – karnok Jul 03 '11 at 15:25
  • It makes perfect sense. Remember that each application in android runs in it's own Java Virtual Machine. Bootstrapping a VM can take significant amount of time, killing an application is fast on the other hand. There is a high chance that when application was started, it will be "poked" in a moment again, for one of the above reasons... And if the application does not run any threads in background, it actually ONLY takes some memory, not CPU, nor I/O. And memory can be reclaimed pretty quick by killing the application. So it makes perfect sense. – Jarek Potiuk Jul 03 '11 at 15:30