一、在活动中使用 Menu
1、在 res 目录下新建 menu 文件夹,接着 在这个文件夹下新建 (Menu resource file);
重写:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.add_item:
break;
case R.id.remove_item:
break;
default:
}
return super.onOptionsItemSelected(item);
}
二、Intent
显式:
Intent intent =new Intent(MainActivity.this,Project_Home_Activity.class);
startActivity(intent);
隐式:p44
电话:
Intent intent =new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:10086"));
startActivity(intent);
网页:ACTION_View
Intent intent1 =new Intent("com.yidaichu.kotlintest.ACTION_START");
intent1.putExtra("extra_data","Hello Home Activity");
startActivityForResult(intent1,1);
Intentintent =new Intent();
intent.putExtra("data_return","Hello FirstActivity");
setResult(1,intent);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (1 == requestCode) {
Log.w("MainActivity",data.getStringExtra("data_return"));
}
}
二、活动的生命周期
onCreate() -> onStart() -> onResume() -> onPause() -> onStop() -> onDestroy()
onRestart()