java - how to get data from one service to another in android -


i new android development, working on project in have create 2 service namely service1 , service2.

my service1 run while starts new service called service2 run time perform work , stop.

service2 has read/access , change value of data members of service1 , destroy automatically every time after completing execution.

till came know want perform inter service communication.

i dont know how this... kindly me solve problem.

service1 code snippet

class service1 extends service{         private int counter = 0; //some code @override         public void oncreate() {             // todo auto-generated method stub             super.oncreate();  intent i= new intent(this,stratcounterservice.class);         startservice(i); } //some code     public int getcounter() {             return counter;         } 

this code using in class service1.java

service2 code snippet

public class service2 extends service{      @override     public ibinder onbind(intent intent) {         // todo auto-generated method stub          return null;     }      @override     public void oncreate() {         // todo auto-generated method stub         super.oncreate();          thread timer = new thread(){             public void run(){                 try{                     sleep(20000);                 }catch(exception e){                     e.printstacktrace();                 }finally{                     if(getcounter()>=someinteger) dosomthing();                     else {                         minitialized=false;                         //and stop service here!                         stopself();                     }                 }             }         };         for(int i=0;i<3;i++) timer.start();     }      @override     public void onrebind(intent intent) {         // todo auto-generated method stub         super.onrebind(intent);     }       @override     public void ondestroy() {         // todo auto-generated method stub         super.ondestroy();     }      @override     public int onstartcommand(intent intent, int flags, int startid) {         // todo auto-generated method stub         return super.onstartcommand(intent, flags, startid);     }   } 

thanx in advance..

you can use shared preference store data , can service class

sharedpreferences


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -