I know there are several questions of this type, but I have tried all this and it still does not work.
Good for my application; I have an Activity. There are 4 tabs in this exercise, and the fourth is a list and a record button. When I click record, the GPS receiver starts. Having received a new gps value, he pushes it into the list.
It still works!
If I press the Home button, it will still work if I put it aside. It resumes action with a specific tab, and the list still holds the list, and the gps listener is still active.
This is also great! Now I wanted to add a notification that shows the number of gps values in the list as .number. On each new GPS signal, it updates the notification icon with a new number. This is not a problem, but the click action of a notification completely hides my application.
The actual code is as follows:
public void callNotify(String text) { notif = new Notification(); Intent contentIntent = new Intent(this, tabactivity.class); contentIntent.putExtra("fid", this.specialvalue); contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notif.icon = R.drawable.icon; notif.setLatestEventInfo(this, getString(R.string.app_name), text, PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); notif.ledARGB = Color.RED; notif.ledOnMS = 200; notif.ledOffMS = 200; notif.flags = Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_ONLY_ALERT_ONCE; notif.number = notifyNumber; mNotificationManager.notify(notifyNumber, notif); } public void updateNotify(String text) { notifyNumber++; notif.number = (int) (notifyNumber / 2); Intent contentIntent = new Intent(this, tabactivity.class); contentIntent.putExtra("fid", this.specialvalue); contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notif.setLatestEventInfo(this, getString(R.string.app_name), text, PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT)); mNotificationManager.cancel((notifyNumber - 2)); mNotificationManager.notify(notifyNumber, notif); }
So, updateNotify () is called in a new gps signal. And callNotify () is the first before it starts the gps listener. And, yes, notifyNumber / 2 was my intention, because I work with this number more.
If I compile it like this and click "Notification", it will open a new tab in the first tab. If I click then I will have many errors (database is still open, null, etc.). I think because it starts a new tabactivity, and the other is still open, because I see that the gps listener is still working.
So, I want me to be able to do the following: I open the application, go to the tab, open the tab 4, record the record. If I click, then he should hide the application, also if I just press the home button. But there is a notice. If I click on him, he must again show hidden activity, and that’s all. So what am I doing wrong there? I thought the flags FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP should solve the problem?