I'm trying to add functionality to my foreground service notification to just open the app when the notification is clicked. I don't want to run any activity - I just want to display the app.
Basically I want to achieve same thing that can be achieved in Android by bringing list of apps and clicking on one).
I've checked lots of posts on StackOverflow, but all of them use activity class in Intent, while I don't care about any particular activity - I just want to bring the app up.
You must have a launcher activity right? so you always can start an activity with your launcher activity and use a launch mode in the AndroidManifest.xml to define to bring it up if it already has been created.
Related
Im coding an app that should replace the oem launcher on my Android-HeadUnit.
Now I want to detect inside my App if the Home-Button is pressed, in order to go to the homescreen of my launcher. This should only happen if the launcher is already in the foreground.
For instance, when I'm browsing in the app-drawer, and I press the home button instead of the back-button, it should still get me to the homescreen.
I've already tried some things with Key-Detection, but it seems that this method is depreciated since lolipop.
My app should run on Api 23 and above.
Foreground app is unable detect and intercept Home button click. Because this is the only guaranteed way for user to close this app and return to home screen. Same for recent apps button
When you press Home button intent with category android.intent.category.HOME is sended to system. That way you know what activity will receive that intent, because this launcher is yours app. I've never developed launcher app but I suppose you may catch this intent is onNewIntent if your activity launchMode != standard
I've implemented OneSignal push notifications in my Android app. I'd sending push notifications with URL as a payload attatched to them. That URL sends an intent that can be opened by another activity of my app or the browser. So, when some activity of my app is in foreground and I choose to open the notification in my app, there are 2 instances of my app. So, even if a user taps Exit in the now top-most activity, the one that was already opened still remains. Basically, users have to exit twice from my app (and possibly more times if this keeps on happening).
So, is there any way by which I can finish the foreground Activity when the user taps on the notification (and chooses to open it in my app instead of the browser) and then proceed..?
Also, I have tried all the launch modes: normal, singleTop, singleTask and singleInstance, all produced the results that they were designed to, but, none could suit my case.
I don't know which code should I include here.
If this can't be done, is there any way to launch all activities of my app (no matter from where they're launched) into the same instance?
For this you will have to start activity from notification by using activity flag like this
yourintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
it will clear foreground activity instance and your new activity instance create on top.
I've developed an android app where you can customize your own widget.
My problem: I want to start an Intent when an instance of the widget is added to the homescreen.
Until now I'm using the onReceive() method, which is called by the system in my AppWidgetProvider class as soon as anything happens. There I wait for an Intent which is sent by the system and which has the intent action
AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED
(onWidgetDataOptionsChanged() is according to android developer page the right method: http://developer.android.com/guide/topics/appwidgets/index.html).
I've tried this on several real devices and it always works. But on all emulators with new android versions, no Intent with the above mentioned action is sent by the system when I add a widget instance to my homescreen.
So, is the issue caused by the emulators or should I wait for another kind of action?
Good day everyone, I am here to ask about onesignal notification on android. I want to return to the app's previous state/page when the notification is clicked. thank you for your help on advance.
You can customize which activity you want to show when a OneSignal notification is opened if the launcher Activity defined in your AndroidManifest.xml isn't what you want. See Open a different Activity at the bottom of the Android Customizing Notifications documenation.
The OneSignal SDK currently does not have an option to resume the app at the current Activity however you can use the above to create an Activity that will just close when opened to make Android go backward to your last active Activity.
Thanks.
In iOS, there is a way to register custom scheme, and it is possible to open a whole app, like new instance or one with some app state (running) and it is not just a single ViewController.
For Android i am looking for a way to have whole stack of activity recovered (that might be launched before launching a browser) after user clicks a link that redirects to my app.
I don't want user to have to tap back till he closes the browser and goes back to my app activities, and I don't want to launch just single derived activity - but just go back to my app activity stack with the new one on the top.
Is this possible to achieve in some neat and clean way? Or at least clean activities of the app that were launched before a browser where user clicks a link that opens my app's activity?
Ok, the solution was to create launching activity that would be browsable. This activity would then launch desired activity with flags :
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
and immediately finish itself...