Question about service/notification (example "FakePlayer")

Put your problem here if it does not fit any of the other categories.

Question about service/notification (example "FakePlayer")

Postby cstarling » Tue Jan 31, 2012 2:11 pm


I have a problem with service/notification
My needs/requirements are: I want to have a program running permanently.

Therefore I take a look at the well known example FakePlayer
because this fits to my needs.

My own program attempts according to the example, but also the original-code has the following behavior, which I do not understand:

If the program is started and then the service is started, the desired entry appears in the notificationbar.
If the program is in the background you can put it to front with the notificationbar, this works several times.
You can also use the home screen icon to put it to front with the homescreen-icon with which it was launched, this works several times.
So far, So good...

But in the following sequence:
-start program and start service
-lay program in the background
-put the program to front with the Notifikationbar
-lay program in the background
-put the program to front with the home screen icon
there is the following problem:
The programm is not put to the front, but a new instance is started (onCreate is called). These two instances can be separately killed with 2x back-button.

This behavior generally occurs when mixing the two possibilities of putting the program to front!

Can anyone reproduce this behavior?
What have I misunderstood / what have I done wrong?

My guess is that there is something wrong with the flag in the notification or intent.
However, I have seen at several places on the Internet precisely this use of the flags.

Notification note=new Notification(R.drawable.stat_notify_chat, "Can you hear the music?", System.currentTimeMillis());
Intent i=new Intent(this, FakePlayer.class);
PendingIntent pi=PendingIntent.getActivity(this, 0, i, 0);
note.setLatestEventInfo(this, "Fake Player", "Now Playing: \"Ummmm, Nothing\"", pi);
startForeground(1337, note);

Best regards
Posts: 4
Joined: Tue Nov 01, 2011 8:39 am


Re: Question about service/notification (example "FakePlayer

Postby Phyll » Tue Jan 31, 2012 10:53 pm

Hi cstarling,

I think it obviously is allowing the OS to make another copy of it and those flags in the intents and manifest that would prevent that, most likely are not correct. I thought the default would be to restore it and not make another copy of it anyway. I see the service in the example uses the CLEAR_TOP and SINGLE_TOP neither of which should allow two.

Master Developer
Master Developer
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 12 guests