I would like to know exactly what operation a devices home button performs? ie what intent, intent category and action is issued when you click on home button? that takes on back to the blank home screen. I would like to know what is involved in implementing this operation to occur when clicking on my own custom button. Thanks (PS I know it is not standard, but neither is my device).
Pressing the Home switches you from the app to the home screen, whilst leaving your app running in the background.
The flags you can use to modify the default behavior are: FLAG_ACTIVITY_NEW_TASK. Start the activity in a new task. If a task is already running for the activity you are now starting, that task is brought to the foreground with its last state restored and the activity receives the new intent in onNewIntent() .
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken a text view.
Task affinity lets you define which task an activity belongs to. By default, an activity has the same task affinity as its root activity. With task affinity, we can now separate activities into different tasks. <activity android:name=".Activity_A"
If you want to show the home screen, you can do it by:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Update: check this sample app: http://developer.android.com/resources/samples/Home/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With