Bundle is null after setting it in Intent

前端 未结 2 1370
礼貌的吻别
礼貌的吻别 2020-12-20 16:26

I know there are questions like: android-intent-bundle-always-null and intent-bundle-returns-null-every-time but there is no correct answer.

In my Activity 1

2条回答
  •  悲哀的现实
    2020-12-20 16:36

    Activity 1

    Intent intent = new Intent(getApplicationContext(), MapViewActivity.class);
    
            Bundle b = new Bundle();
             b.putBoolean("asdf", true);
             b.putInt(AppConstants.ID_KEY, id);
             intent.putExtras(b);
    
             startActivity(intent);
    

    Activity 2

    Bundle extras = getIntent().getExtras();
    
     boolean bool = extras.getBoolean("asdf");
     int m_int = extras.getInt(AppConstants.ID_KEY,-1);
    

提交回复
热议问题