Intent Service Class sample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
public class MyIntentService extends IntentService { public static final String Somevariables = "somevalue"; public MyIntentService() { super(MyIntentService.class.getName()); // you can give any string but it is good practice to giving classname } @Override public void onCreate() { super.onCreate(); //--some code -- } @Override protected void onHandleIntent(Intent intent) { //you can retrive intent extras String msg = intent.getStringExtra(EXTRA_KEY); //--actual backgroung code gos here -- } } |
Add service in manifest also
1 |
<service android:name=".MyIntentService"/> |
ref: https://developer.android.com/training/run-background-service/create-service.html
1 Like