I am new to android and i have been analyzing the android source code to understand how the System services are implemented. My Question is am I able to create my own System Se
public class MyService extends Service {
private static MyService instance = null;
public static boolean isInstanceCreated(){
return instance != null;
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
//Toast.makeText(this, "onStart", Toast.LENGTH_SHORT).show();
}
@Override
public void onCreate() {
super.onCreate();
instance = this;
new Thread(threadBody).start();
}
@Override
public void onDestroy() {
instance = null;
}
}
In your activity:
if(!MyService.isInstanceCreated())
startService(new Intent(YourActivityClassName.this, MyService.class));