android - Service killed before starting loop -


i new in android development. service killed before starting loop.. started service activity mainactivity

    package com.example.ch_m_usman.sharedtasklist.services;             import android.app.intentservice;     import android.content.intent;     import android.util.log;      public class reminderservice extends intentservice {                    public reminderservice() {             super("reminder service");         }          @override         protected void onhandleintent(intent intent) {     log.e("check","")        //loop not start.             (int i=0;i<5;i++){                 log.e("inside for","");             }        }      } //how use loop in intent service 

use below code:

public class taskconfirm extends intentservice {           private final ibinder mbinder = new localbinder();           public taskconfirm() {             super("taskconfirm");             setintentredelivery(true);         }          @override         public void oncreate() {             super.oncreate();            //initilise objects here below...              taskidlist=new arraylist<string>();         }          @override         public int onstartcommand(intent intent, int flags, int startid)         {              return super.onstartcommand(intent, flags, startid);         }          @override         protected void onhandleintent(intent intent) {              // intent data here below if required......              if (intent != null) {                 string  taskid=intent.getstringextra("taskid");                 }                // apply loop here .......                  (int i=0;i<5;i++){                     log.e("inside for","");}           }     public class localbinder extends binder {        public taskconfirm getservice() {             return taskconfirm.this;         }     }       @override     public ibinder onbind(intent intent) {         return mbinder;     }       } 

start service below activity :

 intent serviceintent = new intent(context, taskconfirm.class);      // put data if required      serviceintent.putextra("taskid","1");      startservice(serviceintent); 

if want access service in other activity bind activity service:

 protected void onstart() {             super.onstart();              intent intent = new intent(this, taskconfirm.class);             bindservice(intent, mconnection, context.bind_auto_create);         }    private serviceconnection mconnection = new serviceconnection() {          @override         public void onserviceconnected(componentname classname,                                        ibinder service) {              taskconfirm.localbinder binder = (taskconfirm.localbinder) service;             mservice = binder.getservice();             mbound = true;            // task on service-connected...          }          @override         public void onservicedisconnected(componentname arg0) {             mbound = false;         }     }; 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -