Android中Intent的获取问题

public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        Intent intent=new Intent(this,SecondActivity.class);
        startActivity(getIntent());
        return true;
    }
    return super.onOptionsItemSelected(item);
}

为什么startActivity(Intent)方法输入getIntent()方法无法获取到Intent对象啊?点击菜单选项无反应。

getIntent是应该你在SecondActivity做的,你这里只需要传intent就可以了。

 startActivity(getIntent());
 这应该是传入你上一行代码的intent吧
 startActivity(intent);

getIntent方法意思是获取其他页面传递过来的意图Intent,这里因为没有,所以为null,你应该传递上面new的那个Intent对象,这样你启动了以后,跳转过去的页面中使用getIntent就会接受到你传递的这个Intent

startActivity(getIntent())改成startActivity(intent)

getIntent是获取其他页面启动本activty时调用的Intent, 你当前activty并没有被其他页面启动, getInent就是空的了

getIntent 是第二个界面获取第一个界面传的值。第一个界面使用intent.putExtra("数据名", 数据)传递的,你这是第一个界面,是获取不到值的