Skip to content

Instantly share code, notes, and snippets.

@talayhan
Last active August 30, 2017 21:16
Show Gist options
  • Select an option

  • Save talayhan/f5462d457ff6284649d0 to your computer and use it in GitHub Desktop.

Select an option

Save talayhan/f5462d457ff6284649d0 to your computer and use it in GitHub Desktop.
Android Thread Tips and Tricks
/* You can run thread as specifically time 1 minute, 1 second, 1 hour etc. Whenever you want. */
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
// do something here.
sendThread();
}
}, 0, 1, TimeUnit.SECONDS);
/* Certainly, kill process on android when you press the home button. */
@Override
protected void onPause() {
super.onPause();
android.os.Process.killProcess(android.os.Process.myPid());
}
/* below code is the other way how to quit */
getActivity().finish();
System.exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment