How To Send Application To Background?
Solution 1:
Intenti=newIntent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
Home key press event cannot be captured as an android security feature.
Solution 2:
You can send your activity into the background using moveTaskToBack
.
There's no way to catch a HOME key press, or even to detect that it was pressed. The closest you can come is to write a replacement Home screen that uses android.intent.category.HOME. I believe that the user would have control over which activity should get to handle such an intent.
Solution 3:
You can't catch the home key... it would defeat it's purpose after all.
Solution 4:
If you simply want to know when your Activity is no longer visible, override the onPause() and/or onStop() methods.
If you want to start doing something in the background at this point, you could create a Service. A Service will run in the background, unlike an Activity which is more likely to be killed.
If you want to send some data to this Service from your Activity, you can use Intents and Extras. If you want to send more than the simple types of data you can send with extras, use the Application class. (Described in more detail here)
Post a Comment for "How To Send Application To Background?"