I want to make an app that has it's sole purpose of switching to the home screen (See backstory). I don't know the behaviour on other phones, but on the Honor 8, clicking the home screen button first switches to the previous home screen, then re-clicking the home screenbutton switches to the default home screen. Sorry, I don't know the technical term to differentiate between the home screens and the "home-home screen", the home screen with the highlighed house. This home screen is not accessible with one click on the home screen button.
I have a working solution now, but it has two main cosmetic flaws:
Since the Honor 8 needs two clicks on the home screen button it has been implemented twice in the source code. Because of animation I also need a delay:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//Came with the hellow world app and apparently cannot be removed
super.onCreate(savedInstanceState);
//First "virtual click" of home button
startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
//Delay to allow the animation to complete
try {
Thread.sleep(800);
} catch (InterruptedException e) {
//Not really doing anything clever
}
//Second "virtual click" of home button
startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME));
//Close the app. (I know, it's deprecated)
this.finishAffinity();
}
}
This is not a very elegant solution. Going directly to the "home-home screen" would be much leaner but if there is a solution out there it's hard to find amought the dosens of answers how to go to the home screen.
Any nudge in the right direction is appreciated.
Backstory:
I've got the Honor 8 and I want to configure single click on the smart button to show the home screen. That's not an option, but the button can launch an app the shows the home screen. Because, who would want to go directly to the page with the most information when the phone is unlocked, right?
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.