Go to Homescreen on Homebutton press inside my launcher-app - java

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

Related

Bring app to the front when notification is clicked

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.

Finish an activity before starting the other one from notification

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.

Get notified when instance of app widget was added to homescreen by user

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?

Intent-filter Browsable for and android Application, not Activity?

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...

Always resume back at my app's main form/activity

My Android app has a button that executes this code in order to open the app market pointing to a certain app.
It works.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(getResources().getString(R.string.app_url)));
startActivity(intent);
But whenever the user exits my app at that point, by hitting HOME, the next time he reopens it (resuming it, even days later), the app is STILL pointing at the app store.
How do I make any "reopening" always return back to my app's make form/activity?
(Same as if he had hit BACK, instead of HOME, when he exited my app yesterday.)
Thanks.
From google + android developers post.
If your application launches the activities of other applications (such as to view a picture or pick an attachment), there is an important intent flag to know:
Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
Use this when starting an activity that you don't want the user to return to if they relaunch your application from the app launcher or a shortcut on the home screen. For example, it would be confusing to tap on the Gmail icon and find yourself selecting a picture because that is the last thing you had been doing as part of the Gmail task.
Before startActivity(), try this:
intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
If you would like the activity that this is called from to clean up & forget its state as well, call finish() after startActivity() too.

Categories

Resources