Created
June 25, 2015 20:50
-
-
Save marcoRS/3f6f469b291183690e94 to your computer and use it in GitHub Desktop.
Background Thread
This file contains 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
public class MainActivity extends AppCompatActivity { | |
public static final String TAG = "MainActivity"; | |
/** You can also choose a cached thread pool to run threads in parallel. */ | |
public static final Executor sExecutor = Executors.newSingleThreadExecutor(); | |
@Override protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); | |
} | |
@Override protected void onStop() { | |
super.onStop(); | |
sExecutor.execute(new Runnable() { | |
@Override public void run() { | |
Log.i("BackgroundThread", "I am sleeping"); | |
SystemClock.sleep(30000); | |
Log.i("BackgroundThread", "I am returned"); | |
} | |
}); | |
} | |
@Override protected void onDestroy() { | |
super.onDestroy(); | |
Log.i(TAG, "I was destroyed"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment