Skip to content

Instantly share code, notes, and snippets.

@sharifulislam52
Last active March 1, 2018 15:22
Show Gist options
  • Save sharifulislam52/7a907db5ed3d2cf177f45d4ab192e461 to your computer and use it in GitHub Desktop.
Save sharifulislam52/7a907db5ed3d2cf177f45d4ab192e461 to your computer and use it in GitHub Desktop.
/**
* create service
*/
public class service_Name extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// when service start this method will run
return START_STICKY;
}
@Override
public void onDestroy() {
// if we call this method service will destroy
super.onDestroy ();
}
}
/**
* call service from activity
*/
startService(new Intent(current_activity_name.this, service_Name.class));
//service_Name, current_activity_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment