Android - Background Service

摘要:Android - Background Service

in Activity write 

startService(new Intent(this, YourService.class));
Service Class
 
public class YourService extends IntentService {

    private final String TAG =  YourService .class.getSimpleName();

    public YourService () {
        super("YourService ");
    }

    @Override
    public void onCreate() {
        Log.i(TAG, "onCreate");
        super.onCreate();
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        //DO Your Some thing;
    }

      
    @Override  
    public  void  onDestroy() {  
        Log.i(TAG ,  "onDestroy" );  
        super .onDestroy();  
    } 
}

 

 
in AndroidManifest write 
    
<!-- service -->

<service
android:name=".YourService"
android:enabled="true" >
</service>