Reputation: 115
I have created an Android app and it's working fine. The issue is that, when I press the back button of the phone, the application is closed, but I want to run the application in background also.
If possible, can anyone provide a pseudo code for the same, or give an idea of what can be used to implement this.?
Upvotes: 0
Views: 100
Reputation: 12664
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK )
{
this.moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
}
Upvotes: 1
Reputation: 4762
You should go with Service if you want your Application's part to run in Background... for E.g: Playing Music at the Same Time Browsing on the Internet
Hope This could help
Upvotes: 0
Reputation: 4499
You should use Service to run you app in background
You can use following tutorials for better understandings
Upvotes: 0
Reputation: 251
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
{
this.moveTaskToBack(true);
return true;
}
return super.onKeyDown(keyCode, event);
}
Upvotes: 1