Anandhu
Anandhu

Reputation: 312

Close the background service on forcefully closing the application

I am receiving some data through bluetooth from arduino board.. this data receiving and data storing to text file is done in a class named BackgroundService which is Extending the Service class..

So Now I want to disconnect the data recieving on Forcefull close of my android application, how can I do that , I tried with onStop(),stopService() methods but its not working..

stopService Method

 @Override
    public boolean stopService(Intent name) {
        // TODO Auto-generated method stub
       Amarino.disconnect(getApplicationContext(), DEVICE_ADDRESS);
       unregisterReceiver(arduinoReceiver);
        return super.stopService(name);

    }

Upvotes: 1

Views: 182

Answers (1)

Zohra Khan
Zohra Khan

Reputation: 5302

You can use onTrimMemory() added in API 14

public abstract void onTrimMemory (int level)
Called when the operating system has determined that it is a good time for a process
to trim unneeded memory from its process. This will happen for example when it goes 
in the background and there is not enough memory to keep as many background 
processes running as desired. 

Check this link. Ver good link which explains how application works and how they are closed on low memory.

Upvotes: 1

Related Questions