markharrop
markharrop

Reputation: 876

Bundle is null from third activity

I'm using bundle to pass a string from my MainActivity to my second activity which is sub genre. But I also need the same string in my third activity.

I use my code like this in my main activity

     Bundle getGenre_Bundle = new Bundle();
            if (genre.equals(selector.Crime)) {
             Intent i = new Intent(getBaseContext(),Crime.class);
                getGenre_Bundle.putString("crime",selector.Crime);
                i.putExtras(getGenre_Bundle);
                startActivity(i);

Then I call it in my second Activity using

 Bundle p = getIntent().getExtras();
    Genre = p.getString("crime");

This works great but if I try to call it on my third activity it returns an error in my log that my firebase child(Genre) can't be null.

I've fixed the problem by making a new bundle in my second activity that recollects the String to pass to my third activity. But it seems a bit of a messy way of doing it. Is there an easier/better way to pass strings to any activity?

Upvotes: 0

Views: 44

Answers (1)

Yash Fatnani
Yash Fatnani

Reputation: 91

You can fetch entire bundle from your previous activity in second activity and simply set in intent with putExtras()

Bundle old = getIntent().getExtras();
Intent thirdActivity = new Intent(this,thirdActivity.class);
thirdActivity.putExtras(p);

Upvotes: 1

Related Questions