0

I need to pass some value from 1st activity into the third. I already pass it form 1st to 2nd like this.

my 1st activity: (I do it in on create method)

mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent intent = new Intent(DisplayRecepit.this, DisplayLogs.class);
    intent.putExtra("recepitID", receiptList.get(position).getId());
    startActivity(intent);
    }
});

And I recieved it in 2nd activity like this: (I do it in on create method)

final long forwardedId = (long) getIntent().getExtras().get(String.valueOf("recepitID"));
List<Logs> logsList = new Select().from(Logs.class).where("Receipt = " + forwardedId).execute();

Now I need somehow pass it from 2nd activity to my third activity.

In my 2nd activity I have a button that takes me to 3rd activity.

I saw some examples on web but I didn't make my app working, so any help is welcome.

Question: I have pass value via intent from 1st activity to 2nd activity. How should I pass this same value from 2nd activity to my 3rd activity?

RubyDigger19
  • 835
  • 13
  • 38
  • Just the way you did it in the frst one, do it in the second one, what is the issue? – varunkr May 06 '16 at 09:32
  • In same way as passed from 1st Activity to 2nd Activity, is then any issue when passing `recepitID ` from 2nd Activity to 3rd? – ρяσѕρєя K May 06 '16 at 09:32
  • 1
    Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – varunkr May 06 '16 at 09:33

3 Answers3

0

In your second activity pass this value using intent

Intent i = new Intent(getApplicationContext, Third.class);
i.putExtra("forwardedId",forwardedId);
startActivity(i)
Damini Mehra
  • 3,257
  • 3
  • 13
  • 24
0

First you have to pass data to 2nd Activity.then you can pass from 2nd to 3rd Activity.

ananya
  • 1,001
  • 6
  • 33
  • 50
0

Using default android mechanism its not possible. Still if you cant to achieve this you can use Eventbus : "https://github.com/greenrobot/EventBus" where you post message (can be anything a string, integer, even a class pojo with arrylist) from first activity and catch it anywhere.

Go to above mentioned link add the dependency in your app level build.gradle and sync it.

Create this event Pojo :

    public class SomeEvent {
    private ArrayList<String> message;

    public SomeEvent(ArrayList<String> message) {
        this.message = message;
    }


    public ArrayList<String> getMessage() {
        return message;
    }

}

Activity 1 :

in onResume() do this :

EventBus.getDefault().register(this);

in onDestroy() do this :

EventBus.getDefault().unregister(this);

to post an event :

Do this only after Eventbus registration.

EventBus.getDefault().post(new SomeEvent(some arraylist);

Now in Activity 3:

just write this method. Don't call it explicitly. Eventbus handles that internally. Make sure the argument of this method is your event class which you post in Eventbus.

public void onEvent(SomeEvent event){
  // you got your arraylist which you posted from Activity 1;
  ArrayList<String> list = event.getMessage();
}