Android: If app loaded from notification, doesn't show in task manager - android

Not sure this is supposed to happen but to replicate:
Kill the app
Send a push notification via GCM to the app
Tap on the push notification (which loads the app)
The app then loads with the Activity set in the PendingIntent
Then tap the home button
Now bring up the task manager and notice the app is no longer there.
Has anyone seen this before, as it doesn't seem to happen for any other apps I've seen on the store?

So to answer my own question, the reason this was happening was because the Activity I had in my PendingIntent didn't have the LAUNCHER category associated with it.
So when the Activity was loaded, it didn't actually load the entire app but just the Activity on its own. I.e. the Activity was just loaded as a sheet "on top" of the UI.
So to fix, I just changed the PendingIntent to point to my MAIN activity, and when that was loaded, read the extras from the intent and then load the related Activity.

Related

How to trigger pop-up in app via notification click even when app is not running

I'm trying to implement a timer in my app. The timer runs in a foreground service, and it works as intended.
Upon clicking the the notification, it should a) open the Timer activity (which is the Main activity) and b) open a one-time pop up asking if you want to stop it. (not the full extent of the pop up, but I've simplified it for this example).
I am having difficulty with this functionality because of a few challenges/limitations. My two main methods is using RxJava and broadcast receivers via Pending intents.
If the app is open and in the foreground, I can use an observable via a broadcast intent and listen to it the Timer activity. when it receives a value, it shows the pop up. Simple.
If the app is closed or in the background, I've tried using a pending intent with a key-value extra such as ("should-show-pop-up",true). I then check in the onStart method if this extra exists and if true, show the pop up. However, now it shows the pop up every time I open the app. If the app goes in the background and then back to the foreground, the activity still holds that extra and it triggers the pop up.
So bottom line: how do I open my app and show a pop up if a user presses a notification? Even if the app is closed or in background
Best way to do this is to use a separate Activity for this not your main Activity. When you create the Intent to put into the Notification, add the following flags:
Intent.FLAG_ACTIVITY_NO_HISTORY
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
This will ensure that the Intent with the "extras" does not become the "default Intent to use when your app is launched from the HOME screen"

Check if "setFullScreenIntent" leads to a launch of the application or to the display of a notification

I get a firebase notification and create a NotificationCompat.Builder with the "setFullScreenIntent" option. This leads to different behaviours on different systems or different device status.
Sometimes the app launches directly, sometimes a notification is displayed.
I have to surpress a ringtone if the user clicked on the notification but play it when the app starts directly.
How do I get to know which one happened when my activity starts?
Sorry for my English.
You can do cancel the Notification in activity#onCreate or other lifecycle where you want

Deciding which activity to open on notification click

I'm currently trying to find out, how to specify the destination activity on click on an android notification - but not until actually clicking the notification.
I have the following use case: I have an app where the user has to log in before using it. So if the user receives a notification from my app while he is authenticated and using the app in foreground, a click on the notification should lead to lets say ExampleActivity. But if the app is in background and a notification is received, a click should redirect to LoginActivity, where the user has to authenticate first.
Since the destination activity is specified when creating and setting the Intent to the NotificationCompat.Builder, I have no later control over the destination activity.
So if the user is logged in and receives a notification, closes the app and clicks on the notification, he gets redirected to ExampleActivity, even though he would have to log in beforehand, which is a security flaw for my process.
I feel like, there should be a common approach on how to solve this kind of problem. Is there a possibility to check if the app is running during click on the notification and decide where to redirect the user to?

GCM - Opening app from notification?

I'm working on an app which is using GCM for push notification.
My question is around how to open/start the app from when user clicks the notification.
I have two potential scenarios:
A) The app is open and is resident in either foreground or background, either way my GCM works fine, the GCM message arrives user taps notification and intent starts relevant activity (passed via the notification pending intent).
B) The app is closed and notification received, the user again taps the notification and the intent tries to start the relevant activity and this is where it gets messy.
The app has a back-end and so needs to auto-login/authenticate now if I try to start the same activity the credentials etc are out of date or dont exist therefore the app crashes. I need to launch the app from scratch in this case rather than simply start the particular activity via the pending-intent.
My question therefore is how do I tell the GCM listener to check if app running and if so simply start activity and if not (app is closed) launch app as normal?
thanks.
Ok solved this, not sure if its the best way but appears to work without issue.
What I ended up doing was creating a static boolean variable in launcher activity.
This is set true when app starts and the GCM listener tests for this variables state on incoming GCM notif (will always be true for life of app instance), if true go directly to activity else (app closed or stale) launch app.
This seems to work fine from what I can see, still interested in a better method as this does seem hackish?

Notifications on an app after it is shut down with the 4.0 android task manager?

I'm using C2DM in my application, and I have a receiver, which sends data to a class in the application. The class creates a notification and notifies the notification manager to post it.
The problem is that this does not work when the app is forced close manually through the settings, as this also (apparently) shuts off the broadcast receiver.
What I get though is that when an app is shut off with android 4.0's new task manager (the one thats similar to 3.0 but a user can also swipe an app to the left or right to shut it off) it behaves differently: the broadcast receiver is still working, as I get the intent from the C2DM message, but for some reason my phone still plays the notification noise, whilst no notification appears in the tray.
I can't figure out what's happening, because there is no way for the sound to play without the notification to appear, as the sound is attached to the notification and plays when it's posted, no other way. But no notification appears.
Any insight on why this might be happening would be awesome, or what the new 4.0 task manager actually does to apps when you swipe them off the list.
Thanks.
Figured it out, the broadcast receiver was still responding but just failing because it was retrieving things from a class that was part of the main app and was now dead, so now the things it needs are stored in sharedprefs, and retrieved before the notification gets sent.
So to answer the question, no swiping an app from the task manager in 4.0 does not "force kill" the app in the same was as the force kill button in the applications menu in settings. It does kill off the app in such that next time you open it, all the activities restart from scratch, just like if you had been in the last remaining activity and pressed back, hereby calling finish() on the last alive task and shutting down the app. broadcast revivers (and services i assume) still are running afterwards.

Categories

Resources