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.
Related
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.
I have an application that uses another library to enter password to get into the app.
It starts my.package.MainActivity and if it is locked, it will show different.lib.package.MainActivity to get password. Then it resumes to my.package.MainActivity, loads data from API and shows them.
You can show some of the data on the widget on the homescreen (here, it doesn't need password). These data are updated every +- hour from running service my.package.MyService.
When my.package.MainActivity is on the foreground, my.package.MyService is running on the background and updating data correctly.
When my.package.MainActivity on the background, my.package.MyService is started as foreground service and notification is shown to user about that. As I understood this is how it works on Oreo.
So.. when different.lib.package.MainActivity is shown I have to run service as foreground service. Otherwise I am getting
java.lang.IllegalStateException:
Not allowed to start service Intent, app is in background.
Is it possible to stop showing this notification while different.lib.package.MainActivity is on the foreground? Or I have to show notification because it is from different package? I have trouble with this because from user point of view it looks like one app is on the foreground and notification shows that the same app is running on the background.
(it is an old and huge application I am maintaing)
i have made an app where i made a unbound service that is continuously requesting to server api, if server send json then notification will show and on notification click i take the user to one activity to show some data. everything working well while apps is opened or background. but when the app is closed, notification showing but when on notification click trigger to specific activity, there is no data showing(data should come through a server req).
what is the best way to do this?
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?
I'm building an Android app which creates notifications. Each notification has a number of additional actions.
The default application (when the user taps on the notification) launches an activity in my app. That's working fine.
When the user swipes the notification to dismiss the notification, my app responds by doing some deletion work, and the user is left on the list of notifications. The one that the user swiped is removed from the list.
For some of my additional actions I want to launch activities, and that's working fine; for the other actions, I want my app to do some work but I also want the user to remain on the notification list. I'm struggling to find a way to do this last part - all my attempts to configure the intent and pending intent for my additional action result in behaviour whereby when the user clicks on the action, the notification list disappears.
Is there any way to get what I want (i.e. a notification additional action which performs work but leaves the user on the notification list)? Do I need to build a custom notification layout or something?