How to pass same String value from adapter to two different activities

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("", 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


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.

Category:java Time:2018-12-05 Views:1
Tags: java android

Related post

  • how to pass a string value from one view controller to another view controller 2009-11-06

    hi i am new to objective c. i have a login view controller with .h, .m, .xib files. and after successful login i need to go to the second page. The scenario is this, i am accessing web services. to authenticate the user, i send the username and passw

  • how to pass a string value from one .m file to another .m file 2012-03-27

    Hi i am new to objective c. i have a .m file in which i have the string to be passed. NSString *passedMonth; i am Passing it like this KLTile *kltil = [[KLTile alloc] inittempMonth:passedMonth]; temp month is string in other .m file -(id)inittempMont

  • Passing Query String values from one XAML page to another XAML page - Silverlight 2011-11-28

    I have Page1.xaml and Page2.xaml in Silverlight project. I want to pass query string values from Page1.xaml to Page2.xaml on the click event of a button using code behind. Can you please provide me sample code for this ? 1) How to pass query string v

  • In android how to pass the id value from database to hyperlink? 2011-08-16

    I am working on android project. By considering a list view I am displaying the student name from remote MSSQL Database. I have considered the student name text-view as hyperlink. When I click on the student name it has to display the details of that

  • How to pass any text value from form to Crystal Report? 2009-10-21

    How to pass any text value from form to Crystal Report ? ex: i need to pass "hellow" from Form1 to my Crystal Report , how to do it ? (working in C#) thank's in advance --------------Solutions------------- Create a parameter field in Crystal. You can

  • Pass a string value from one view controller to another 2009-11-07

    I am using this way to pass a string value from one view controller to another but still it's not working. Please help! From the main menu login method I pass a result value of a web service to SecondMenu: - (IBAction)MainMenuLogin_Method:(id)sender

  • How to pass the selected value from select box to a PHP function? 2010-12-08

    I have select box for company whose values are populated from DB and I also have another select box for department. Now I have a PHP function to get the values of department if we pass the id of company into it. I have to use this function to populat

  • How to pass multiple string values to a Button click event handler in C# 2011-03-22

    How to pass multiple string values to a Button click event handler in C#? --------------Solutions------------- If you know the strings before hand you can use an anonymous function to capture and pass the strings string s1 = ...; string s2 = ...; but

  • How to pass a variable value from jquery to java class? 2011-08-01

    Please tell me how to pass a variable value from jquery to java class? --------------Solutions------------- Using jQuery AJAX you could send data to any server side script:

  • passing a string value from C function to Objective code in Xcode 2011-08-31

    I need to use a returned value of a C function in objective C..for Ex:consider a file samplec.h & samplec.c..It contains method definition for display i.e.. char *display() { char *b="Hi"; printf("%s",b); return b; } This returned value should be

  • how to pass a string value into a gridview in C sharp 2010-10-06

    hey i have a query.... i have extracted data from database..currently that information is in a string point is to pass that string value into a gridview in the application..i have already created the gridview with checkbox list fitted i

  • How to pass the string value to function 2011-12-10

    I want to pass the string value to function Function Code Private Function Assign(Div As String) sSQL = "Insert into table2 Select * from table1 Where Divi_Code = '" & Div & "'" Rdoconn.Execute sSQL, rdExecDirect End Function Button Click Cod

  • How to pass a string value as a reference in javascript and change it over there 2010-07-14

    How can I pass a string value by reference in javascript. I want this kind of functionality. //Library.js function TryAppend(strMain,value) { strMain=strMain+value; return true; } //pager.aspx function validate() { str="Checking"; TryAppend(str,"Text

  • How to pass a variable value from one AutoIt script script to the next 2014-11-17

    I am running an AutoIt script and that script calls another AutoIt file. How do I pass a variable value from my first script to the next? --------------Solutions------------- You need to learn the scope concept of a variable (Dim, Global & Local

  • How to pass an input value from a small form into a big form? (PHP, Javascript, URLs) 2010-04-26

    I have a Wordpress website that needs to display a 3rd party newsletter signup form. This sign-up form has lots of fields and takes up its own full page. I want to display a simple "enter email address, hit submit" form at the top of every page. When

  • how to read registry string value from batch file 2010-07-06

    I want to read registry string value, from bat file, and then assing the readed value to variable. I tried the following : FOR %%a in ('REG QUERY HKLM\SOFTWARE\MathWorks\MATLAB\7.10 /v MATLABROOT') DO set MATLAB=%%a echo %MATLAB% but it doesn't work.

  • How to pass parameters or values from report to another? 2011-12-16

    I have designed two reports using Microsoft Reporting Services and MDX queries to pull data from data analysis services. Now I want when I open the first one and click on details it opens the second report and it should pass the two values to the par

  • how to pass the same object one activity to another two different activities 2011-08-25

    I want to pass the same object from one activity to another two different activities. I use same code for both, but it didn't work for one of them. I use these codes to send bitmap. Intent nIntent = new Intent(); nIntent.setClass(getApplicationContex

  • How to return a string value from a bash function 2010-07-13

    I'd like to return a string from a bash function. I'll write the example in java to show what I'd like to do: public String getSomeString() { return "tadaa"; } String variable = getSomeString(); The example below works in bash, but is there a better

Copyright (C), All Rights Reserved.

processed in 5.399 (s). 15 q(s)