I'm trying to port a feature from an iOS app to an Android app. UIKit, the iOS view programming framework, provides the lifecycle method -viewDidAppear:animated:, which is called after the view controller has been presented.
The Android documentation for activity lifecycle management reads that "the foreground lifetime of an activity happens between the call to onResume() and the call to onPause()," but when I add asynchronous dispatch code to an activity's onResume(), it increases the time-to-start of that activity.
How can I start an activity and then do arbitrary work after that activity is running in the foreground?
Edit: I'm using code adapted from the Android "Controlling the Camera" training and the camera API guide; the former reads, "As Android's own Camera application does, the recommended way to access the camera is to open Camera on a separate thread that's launched from onCreate()."
I've got this at the end of my onCreate():
new Thread(new Runnable() { @Override public void run() { mCamera.setPreviewCallback(previewCb); mCamera.startPreview(); previewing = true; mCamera.autoFocus(autoFocusCB); } }).start();
onResume()is firing off a thread or AsyncTask, it shouldn't affect time-to-start much, if at all. Maybe showing your code will reveal something?onResume()is method your after. It might be an issue with setting up for the async work. Could you post that code?