Going to home screen programmatically
You can do this through an Intent.
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
This Intent will start the launcher application that the user has defined. Be careful with this because this will look like your application crashed if the user does not expect this.
If you want this to build an exit button from your app please read this article on exit Buttons in Android
How to open Default Home App screen intent on Android
PackageManager packageManager = activity.getPackageManager();
ComponentName componentName = new ComponentName(activity, YourLauncher.class);
packageManager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
activity.startActivity(intent);
activity.finishAndRemoveTask();
and launcher activity in the manifest:
<activity
...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
How to go to the default home screen of Android programatically?
Try this:
Intent homeIntent= new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(homeIntent);
How to programmatically launch a specific home page in android
Not with the default Home screen.
Tucked away in the Launcher
Activity source (at https://android.googlesource.com/platform/packages/apps/Launcher/+/master/src/com/android/launcher/Launcher.java#822) is this chunk of code (see line 822):
if (!mWorkspace.isDefaultScreenShowing()) {
mWorkspace.moveToDefaultScreen();
}
So it is not possible to specify the specific page.
Yet another android show home screen programmatically
Ok, so I haven't solved the actual two problems in the post, which is related to programming. However, I have solved what I wanted to do (ref backstory).
So basically what I did was to install tasker and tasker app factory. In tasker I made a task to show the home screen. Also here it needs to be executed twice to go to the "home-home screen". Add a delay of 100 ms between the two. It looks very smooth. No windows are popping up and it's a nice smooth transition from what ever app you reside in, to the home screen, then it glides to the "home-home screen". Export this task and configure the smart button to run this when the smart button is clicked.
Related Topics
Using Httpclient and Httppost in Android with Post Parameters
How to Resolve "Duplicate Files Copied in APK Meta-Inf/*"
How to Remove Specific Permission When Build Android App with Gradle
Apache Httpclient Digest Authentication
What Does Transitive = True in Gradle Exactly Do (W.R.T. Crashlytics)
Setting a Spinner Onclicklistener() in Android
Wrong Version of Keystore on Android Call
Java.Lang.Noclassdeffounderror: Com.Google.Ads.Adview
How to Blur Background Images in Android
Proguard and Reflection in Android
Android and Getting a View with Id Cast as a String
Tcp\Ip Client - Ehostunreach (No Route to Host)
How to Delete Files Programmatically on Android
Google Gson Linkedtreemap Class Cast to Myclass
Android - Save Image from Url Onto Sd Card
Polyline Is Not on the Roads: It Goes Straight from One Point to Other