1

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?

Uhehesh
  • 506
  • 2
  • 8
  • 22

2 Answers2

6

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.

JavaCoderEx
  • 336
  • 2
  • 9
2

activity are not made for background processes. Use Service for your background processes.

Mohsin Naeem
  • 12,542
  • 3
  • 39
  • 53
  • Okay. But how to use Service? I want to make my program always available and to check new messages (just like Skype), but how it is possible? Maybe I should use Service just to check messages and to start Activity when notification is clicked? – Uhehesh Jul 15 '12 at 20:19