0

I want to display the server response on multiple screen in header bar in Android? Please, tell me how to do that? I created an abstract class and defined the Asynctask class. In onPostExecute method i am using the textview for displaying the result. Now my question is how all the activities access this textview? I am new with Android. Please, give me the proper way to solve this?

Manish Kumar
  • 71
  • 1
  • 6

4 Answers4

0

May be you can use the shared preference feature of android to save the response.

References are How to use SharedPreferences in Android to store, fetch and edit values and http://www.vogella.com/tutorials/AndroidFileBasedPersistence/article.html

On each activity, you can set the header by referring the value from shared preference.

Community
  • 1
  • 1
ngrashia
  • 9,869
  • 5
  • 43
  • 58
0

Create one base activity and extend that created base activity instead of activity. Create one xml file in base activity, in it only declare your header. nothing else, now to display use that xml and for the other contents you can use your actual xml file. So this one is for to set global header. Now, save your response to Shared preferences and use it throughout the app whenever you need.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
0

Store the value into Shared preferences

SharedPreferences sharedPref = context.getSharedPreferences("app_prefs", Context.MODE_PRIVATE);
// saving
sharedPref.edit().putString("key", "value").commit();
// reading
sharedPref.getString("key", "default");
petlack
  • 216
  • 1
  • 2
  • 9
0

You need to store the response values in Stringbuffer

StringBuffer value =new StringBuffer("your response value");

SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
     SharedPreferences.Editor editor = prefs.edit();
     editor.putString("Identifier",value);
     editor.commit(); //important, otherwise it wouldn't save.

Get the value in next activity

SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
final String myVariable = prefs.getString("Identifier", "value");
learner
  • 3,092
  • 2
  • 21
  • 33