Sending data back to the Main Activity in Android

后端 未结 12 1929
后悔当初
后悔当初 2020-11-22 01:36

I have two activities: main activity and child activity.
When I press a button in the main activity, the child activity is launched.

Now I want to send some dat

12条回答
  •  不思量自难忘°
    2020-11-22 02:15

    Use sharedPreferences and save your data and access it from anywhere in the application

    save date like this

    SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.commit();
    

    And recieve data like this

    SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
        String savedPref = sharedPreferences.getString(key, "");
        mOutputView.setText(savedPref);
    

提交回复
热议问题