0

I have an Activity where I want to show my received date from a Database. Showing my result in a TextView, that's no problem. But I also want to save my received Data in an String value. My Code: Main Activity:

db3 = new DatabaseC529(C529chooseActivity.this,tvC529Cthirdoccupied,tInt3);
db3.execute(methode, date, timeId3);

DatabaseC529: Constructor:

public DatabaseC529(Activity activity, TextView textView, String myValue){  
        this.activity = activity;
        this.ctx = activity;
        this.textView = textView;
        this.myValue = myValue;}

...

protected void onPostExecute(String result) {super.onPostExecute(result);
this.textView.setText(result);
this.myValue = result;
 }

After AsyncTask is completed, the Result is shown in the TextView. But I also want to have the Value stored in my String "tInt3". I created a button (just to check if the Value is stored) to get the content of tInt3 after AsyncTask is completed, but it always shows "null". Code Button:

public void button1 (View view){if(view.getId() == R.id.button1){
        Toast.makeText(this, " " +tInt3, Toast.LENGTH_SHORT).show();
    }

Can somebody please help me???

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
A.St.
  • 1
  • where are you storing value to tInt3? – Nirup Iyer Apr 16 '17 at 12:52
  • Possible duplicate of [How to get the result of OnPostExecute() to main activity because AsyncTask is a separate class?](http://stackoverflow.com/questions/12575068/how-to-get-the-result-of-onpostexecute-to-main-activity-because-asynctask-is-a) – OneCricketeer Apr 17 '17 at 05:37
  • Thank you guys, creating an interface solved my problem – A.St. Apr 18 '17 at 06:22

1 Answers1

0

You can use shared preference to store your string data and then use it.

Saving values:

SharedPreferences.Editor editor = getSharedPreferences(yourpref, MODE_PRIVATE).edit();
 editor.putString("tInt3", Result);
 editor.apply();

Getting Values:

SharedPreferences prefs = getSharedPreferences(yourpref, MODE_PRIVATE);
 String value= prefs.getString("tInt3", "null");
Haris ali
  • 773
  • 1
  • 13
  • 19