Difference between revisions of "How to build a simple Android app"
(Created page with '{{Ecl_menu}} __NOTOC__ == Activity Lifecycle ==') |
(→Activity Lifecycle) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
== Activity Lifecycle == | == Activity Lifecycle == | ||
+ | <source lang="java"> | ||
+ | package cs.ecl.mobile.android.simple; | ||
+ | |||
+ | import android.app.Activity; | ||
+ | import android.os.Bundle; | ||
+ | import android.widget.Toast; | ||
+ | |||
+ | public class ActivityLifecycle extends Activity { | ||
+ | |||
+ | @Override | ||
+ | public void onCreate(Bundle savedInstanceState) { | ||
+ | super.onCreate(savedInstanceState); | ||
+ | setContentView(R.layout.main); | ||
+ | Toast.makeText(this, " onCreate", Toast.LENGTH_SHORT).show(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected void onStart() { | ||
+ | super.onStart(); | ||
+ | Toast.makeText(this, " onStart", Toast.LENGTH_SHORT).show(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected void onResume() { | ||
+ | super.onResume(); | ||
+ | Toast.makeText(this, " onResume", Toast.LENGTH_SHORT).show(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected void onRestart() { | ||
+ | super.onRestart(); | ||
+ | Toast.makeText(this, " onRestart", Toast.LENGTH_SHORT).show(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected void onPause() { | ||
+ | Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show(); | ||
+ | super.onPause(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected void onStop() { | ||
+ | Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show(); | ||
+ | super.onStop(); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | protected void onDestroy() { | ||
+ | Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show(); | ||
+ | super.onDestroy(); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | Run the app and try to understand the sequences of message based on diagram from [http://d.android.com/guide/topics/fundamentals/activities.html android developers site] | ||
+ | |||
+ | [[Image:activity_lifecycle_1.png|700px]] | ||
+ | |||
+ | The entire source code for this application could be found at: [https://zenit.senecac.on.ca/svn/ecl500/Lectures/trunk/w11-mobile-android-simple/ sample that illustrates the activity] |
Latest revision as of 22:22, 8 March 2011
Main Page · Course Description · Course Topics · Schedule, Students, Teams · Course Resources · Course Projects
Activity Lifecycle
package cs.ecl.mobile.android.simple;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class ActivityLifecycle extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(this, " onCreate", Toast.LENGTH_SHORT).show();
}
@Override
protected void onStart() {
super.onStart();
Toast.makeText(this, " onStart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
super.onResume();
Toast.makeText(this, " onResume", Toast.LENGTH_SHORT).show();
}
@Override
protected void onRestart() {
super.onRestart();
Toast.makeText(this, " onRestart", Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
super.onPause();
}
@Override
protected void onStop() {
Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show();
super.onStop();
}
@Override
protected void onDestroy() {
Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show();
super.onDestroy();
}
}
Run the app and try to understand the sequences of message based on diagram from android developers site
The entire source code for this application could be found at: sample that illustrates the activity