0

I have an TicketAdapter class in onClick method I'm passing a String value (i.e ticket.getId()) where ticket is my pojo class) to TicketDetailActivity class, I also want to pass same value to one more activity i.e SaveTicketDetailActivity class

public class TicketAdapter extends BaseAdapter {
protected List<Ticket> tickets;

public void onClick(View v) {
    Activity activity = getActivity();
    Intent intent = new Intent(getActivity(), TicketDetailActivity.class);
    intent.putExtra("com.qurater.csr.ticket.id", ticket.getId());
    getActivity().startActivity(intent);
    activity.overridePendingTransition(R.anim.slide_left_detail, R.anim.stay_in_place_detail);
}

Here as soon as I click when intent is fired I'm getting the value (i.e ticket.getId())in TicketDetailActivity class.

Now I want same value to get as an reference in SaveTicketDetailActivity.class I want this value as I'm sending some string data to the server the URL needs id and the data. Thanks

Filip
  • 1,824
  • 4
  • 18
  • 37
Rakesh
  • 43
  • 1
  • 1
  • 10
  • you want to move in TicketDetailActivity.class class right? but from which class you want to go there ? – Hiren Patel Jun 10 '15 at 18:00
  • Why you create an activity for syncing? you can just just create an AsyncTask instance and pass the context and other arguments to it. – strings95 Jun 10 '15 at 18:27

1 Answers1

0

I can hardly imagine a scenario when the data needs to be passed to two activities in parallel. Maybe you can pass the data into TicketDetailActivity and from there pass it to SaveTicketDetailActivity if needed? Furthermore, using entirely new activity for the purpose of sending data to server seems an overkill. You got two better options:

  1. If the data needs to be synced once its details are shown - add this logic to TicketDetailActivity in onCreate() (the simplest approach is to use AsyncTask)
  2. If you want to implement Sync button in SaveTicketDetailActivity and sync the data when the button is pressed - this is bad user experience. A better design is to have this button in TicketDetailActivity.

Said that, if you still want to share a small amount of data between multiple activities, your best option is to use SharedPreferences. See this question for short tutorial.

Community
  • 1
  • 1
Vasiliy
  • 16,221
  • 11
  • 71
  • 127