I want to open pictures in the action from the fragment pass the path to the picture

public void openImage(String image) { Intent intent = new Intent(getActivity(), FullscreenActivity.class); Bundle b = new Bundle(); b.putString("image", image); intent.putExtras(b); startActivity(intent); } 

and I want to get the path that I put in the Bundle

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer_layout); if(savedInstanceState == null) { loge("savedinstance == null"); } String image = savedInstanceState.getString("image"); ImageView imgView = (ImageView) findViewById(R.id.imageView4); imgView.setImageDrawable(Drawable.createFromPath(image)); } 

it turns out that bundle is null and accordingly issues an exception

    1 answer 1

    You are using the wrong Bundle . To get your "image" in onCreate back, you need to do this:

     String image = getIntent().getStringExtra("image"); 

    Bundle savedInstanceState is not meant for that. Doesn't his name bother you at all?

    You shouldn't use the Bundle for this at all, just make it

     intent.putExtra("image", image);