80,351
社区成员
发帖
与我相关
我的任务
分享
public class MainActivity extends Activity {
String Tag="MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.v(Tag, "mainOnCreate");
Button bt=(Button)findViewById(R.id.button1);
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(getApplicationContext(),TwoActivity.class);
intent.putExtra("name", "guanguan");
startActivity(intent);
}
});
//bt.setOnClickListener(l);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onResume()
{
super.onResume();
Log.v(Tag, "mainOnResume");
}
public void onPause()
{
super.onPause();
Log.v(Tag, "mainOnPause");
}
public void onStop()
{
super.onStop();
Log.v(Tag, "mainOnstop");
}
public void onDestory()
{
super.onDestroy();
Log.v(Tag, "mainonDestory");
}
public void onRestart()
{
super.onRestart();
Log.v(Tag, "mainonRestart");
}
}
public class TwoActivity extends Activity{
String Tag="MainActivity";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.two_activity);
Log.v(Tag, "TwoOnCreate");
TextView textview=(TextView)findViewById(R.id.textView2);
Intent intent=getIntent();
String name=(String) intent.getCharSequenceExtra("name");
textview.setText("欢迎你"+name);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onResume()
{
super.onResume();
Log.v(Tag, "twoOnresume");
}
public void onPause()
{
super.onPause();
Log.v(Tag, "twoOnPause");
}
public void onStop()
{
super.onStop();
Log.v(Tag, "twoOnstop");
}
public void onDestory()
{
super.onDestroy();
Log.v(Tag, "twoonDestory");
}
public void onRestart()
{
super.onRestart();
Log.v(Tag, "twoonRestart");
}
}