Code :
package
com.example.activitylifecycle;
import
android.os.Bundle;
import
android.app.Activity;
import
android.view.Menu;
import
android.widget.Toast
public
class MainActivity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(this,
"onCreate", Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu
menu) {
// Inflate the menu; this adds items to
the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main,
menu);
return true;
}
protected void onStart() {
super.onStart();
Toast.makeText(this,
"onStart", Toast.LENGTH_LONG).show();
}
protected void onResume() {
super.onResume();
Toast.makeText(this,
"onResume", Toast.LENGTH_LONG).show();
}
protected void onRestart() {
super.onRestart();
Toast.makeText(this, "onRestart",
Toast.LENGTH_LONG).show();
}
protected void onStop() {
super.onStop();
Toast.makeText(this,
"onStop", Toast.LENGTH_LONG).show();
}
protected void onPause() {
super.onPause();
Toast.makeText(this,
"onPause", Toast.LENGTH_LONG).show();
}
protected void onDestroy() {
super.onDestroy();
Toast.makeText(this,
"onDestroy", Toast.LENGTH_LONG).show();
}
}
Main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="149dp"
android:text="@string/hello_world"
android:textSize="20sp"
/>
</RelativeLayout>
No comments:
Post a Comment