Package is null after installation in Intent

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

In mine Activity 1:

public void goToMapView(Info info) {
    Intent intent = new Intent(getApplicationContext(), MapViewActivity.class);
    //intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    intent.putExtra("asdf", true);
    info.write(intent);
    startActivity(intent);
}

In Info:

public void write(Intent intent) {
    Bundle b = new Bundle();
    b.putInt(AppConstants.ID_KEY, id);
    ... //many other attributes
    intent.putExtra(AppConstants.BUNDLE_NAME, b);
}
public static Info read(Bundle bundle) {
    Info info = new Info();
    info.setId(bundle.getInt(AppConstants.ID_KEY));
    ... //many other attributes
    return info;
}

In MapViewActivity ( Activity 2):

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_view);

    Bundle extras = getIntent().getBundleExtra(AppConstants.BUNDLE_NAME);
    info = Info.read(extras);
    ...
}

The problem is that the packet is extrasalways zero. I debugged it, and Intent ( intent = getIntent()) has all fields equal to null, except for one, indicating what class ( MapViewActivity) it is.

I also tried to deliver the package through intent.putExtras(b)with the same effect. intent.putExtra("asdf", true)applies only to debugging reasons - I also can’t get this data (because it getIntent()has almost all fields set to null).

EDIT

. . .

+3
2

, "", , .

Activity1

    Intent intent = new Intent(Activity1.this, Activity2.class);
    intent.putExtra("asdf", true);
    info.write(intent);
    startActivity(intent);

2

    Bundle bundle = getIntent.getExtras();
    if (bundle!=null) {
        if(bundle.containsKey("asdf") {
            boolean asdf = bundle.getBooleanExtra("asdf");
            Log.i("Activity2 Log", "asdf:"+String.valueOf(asdf));
        }
    } else {
        Log.i("Activity2 Log", "asdf is null");

    }
+3

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);

2

Bundle extras = getIntent().getExtras();

 boolean bool = extras.getBoolean("asdf");
 int m_int = extras.getInt(AppConstants.ID_KEY,-1);
+2

All Articles