Munjal Pandya
Munjal Pandya

Reputation: 115

How to run an Android Application in background?

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

Answers (4)

Kirit  Vaghela
Kirit Vaghela

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

Nitesh Tiwari
Nitesh Tiwari

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

Check this Out

Tutorial Here

Hope This could help

Upvotes: 0

Vaibhav Agarwal
Vaibhav Agarwal

Reputation: 4499

You should use Service to run you app in background

You can use following tutorials for better understandings

Service Tutorial 1

Service Tutorial 2

Upvotes: 0

Mohit marwal
Mohit marwal

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

Related Questions