I have a strange scenario in my application where I want to keep my activity open even though if any notification is clicked. The scenario is I have splash activity that opens the Home Activity and then the OfferActivity(opened through home activity after getting a response). Now I want to remain on the offer activity even after users click on any notification received meanwhile. The problem is all my notification enter into the app through splash screen with intent data and then splash screen pass the data to the home activity which perform the specific action. Please help with your suggestions on the best way to handle it. At the moment I am clearing the notification tray when I opened the offer activity and block the notification display for the moment.
Related
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"
I have an app where users spend most of their time solving puzzles in GameFragment which is in MainActivity. I don't save users progress and if they quit the app before the level gets cleared then their progress for that level is lost and they will have to start anew.
From time to time, I am sending push notifications that when clicked users are given 100 diamonds as a reward.
The problem is, if a user clicks on the notification while playing the game or when the game is in the background, then the game is being recreated from SplashActivity and then goes to MainActivity which hosts GameFragment. Additionally, there are two of the same app are open now in the task bar. What I want is that when user clicks the notification, the notification should disappear and tell MainActivity to reward the user without recreating the whole app again.
How can I achieve this? I am using OneSignal to send push notifications.
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?
We're writing an app that gets events and needs to display a notification about the event in a very noticeable manner to the user. the notification should be like the in-coming call, i.e. full screen, lock all other activities of the same app till user reacts to the notification. the problem is that in the app there's an activity that launches automatically when a timer finishes. and we want to prevent that activity or any other activity to start on top of the notification.
setFullScreenIntent() doesn't give us full screen but a regular heads-up notification, so we tried to implement it by using an activity with flags like:
FLAG_ACTIVITY_SINGLE_TOP
FLAG_ACTIVITY_NEW_TASK
FLAG_ACTIVITY_REORDER_TO_FRONT
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
but that didn't help either.
does anyone have an idea how to implement it? any code examples will be helpful.
I have a notification that notifies that a long operation has succeeded and offers the user to do something after that.
Leaving the notification aside and opening the app, makes the app apear in the recents - even when the back is pressed and the activity stack is left empty.
The problem is that when the user clicks on the notification, the notification intent is then registers in the recents - instead of the app's main activity. Clicking on the recents over and over again does the notification intent action instead of popping up the app.
How can I have the app stay in recents instead of the last notification intent?
Notes:
When the app's activity stack is not empty, everything works perfect!
FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS is not acceptable because it removes the app altogether from the recents instead of just the notification intent.