Android中intent的使用
一、intent
发送intent的Activity
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("key_what",key);
intent.setClass(Activity.this,intentActivity.class);
intent.putExtras(bundle); startActivity(intent);
接收intent的Activity
Intent intent = getIntent();
Bundle bunde = intent.getExtras();
String string = bunde.getString("key_what");
二、在Activity中打开一个Activity:
Intent intent = new Intent();
intent.setClass(ClassOne.this,ClassTwo.class);
startActivity(intent);
不在Activity中,打开一个Activity,如sevice中
Intent intent = new Intent(context, ClassTwo.class);
intent.setClass(context, ClassTwo.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
NOTE:要添加Flags