问题
How to put application (activity?) to background so it can work there?
moveTaskToBack(true);
doesn't work. I have android:noHistory="true"
and this code:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
switch(keyCode)
{
case KeyEvent.KEYCODE_BACK:
moveTaskToBack(true);
return true;
}
return false;
}
What is wrong? How to put application to background?
upd: or maybe I can use moveTaskToBack(true) only in root (MAIN, LAUNCHER) activity?
回答1:
If you want to jump to the home screen because of some activity you can do this:
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
Just make sure you are running the code from your main activity thread. The "startActivity" implies this function is running from the main activity.
回答2:
activity
are not made for background processes. Use Service for your background processes.
来源:https://stackoverflow.com/questions/11495188/how-to-put-application-to-background