Where to get simple Android programs to illustrate the lifecycle?
I was following "hello-android-introducing-googles-mobil… by Ed Burnette.. which was very useful for the basics. Morover using the basics I was able to create a small calculator application.
But when I wanted to work with activities(life cycle) I couldnt follow the book clearly..
So please suggest a book or site which explains the life cycle of android applications 开发者_如何学JAVAwith simple easy to read (and workout) programs
I can suggest two books, but I'd also like to suggest an actual empirical test that you should try.
To answer your original question:
Commonsware is a good source and Mark Murphy has a badge cred on Stack Overflow.
The Busy Coders Guide to Android Development, from Commonsware.com
I've had good mileage on pages 8 & 9 of this book from O'Reilly. I found that in order to fully grasp the Android Life cycle I had to read these pages at least 10 times.
Android Application Development, ISBN 978-0596521479
Suggestion for empirical testing
of the Android activity lifecycle
Create an android Activity or sample app, and log each time one of the Android Lifecycle methods has been entered. As in this sample.
Add these logs entries to your activity, then build it. Run it on a device or on the emulator with adb logcat
running. Then do some experiments. See what happens when you lock the screen,
press home, press 'menu', etc. This method will help you understand than just reading. You will still need to read and study the activity lifecycle, but this will help quite a bit.
public class YourActivity
{
private static final String LOG_TAG = "YourActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d(LOG_TAG, "onCreate()");
super.onCreate(savedInstanceState);
}
@Override
public void onStart()
{
Log.d(LOG_TAG, "onStart()");
super.onStart();
}
@Override
public void onStop()
{
Log.d(LOG_TAG, "onStop()");
super.onStop();
}
@Override
protected void onDestroy() {
Log.d(LOG_TAG, "onDestroy()");
super.onDestroy();
}
@Override
protected void onPause() {
Log.d(LOG_TAG, "onPause()");
super.onPause();
}
@Override
protected void onResume() {
Log.d(LOG_TAG, "onResume()");
super.onResume();
}
}
sams teach yourself android isbn-13: 978-0-321-67335-0
精彩评论