I start an activity from a background service which unlocks the phone and starts an activity. What I want to achieve is to go to home screen just after the activity is loaded. I created a button on the activity that I go to just after unlocking and on its OnClick method I used:
moveTaskToBack(true);
Now, I need to call buttonName.performClick() somewhere but where? I tried onResume and onPause so far, but no luck. How or where can I make sure the activity is fully loaded?
//What I do on my Service to start Activity that unlocks the phone
Intent dialogIntent = new Intent(this, StartStopActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(dialogIntent);
This is the activity class:
public class StartStopActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start_stop);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
Button returnButton = (Button) findViewById(R.id.button3);
returnButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
moveTaskToBack(true);
}
});
//returnButton.performClick();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}