Skip to content

Instantly share code, notes, and snippets.

@mharper
Created September 29, 2011 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mharper/1251818 to your computer and use it in GitHub Desktop.
Save mharper/1251818 to your computer and use it in GitHub Desktop.
Simple activity class to demonstrate Android lifecycle
public class LifecycleActivity extends Activity
{
private int createCount = 0;
private int configCount = 0;
private String sentinel = "";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d("Lifecycle", "onCreate called " + createCount + " times, sentinel is '" + sentinel + "'.");
this.sentinel = "Been here, done that";
createCount++;
}
/** Called when the activity is first created. */
@Override
public void onStart()
{
super.onStart();
Log.d("Lifecycle", "onStart called");
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
Log.d("Lifecycle", "onConfigurationChanged called " + configCount + " times.");
configCount++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment