Last active
August 30, 2017 21:16
-
-
Save talayhan/f5462d457ff6284649d0 to your computer and use it in GitHub Desktop.
Android Thread Tips and Tricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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