-4

I am trying make an get radio button values from first two activities and display/store in the database when submit button in third activity get clicked and sequence of activities is like Activity1->Activity2->Activity3. I have tried shared preference API,getExtra method and intent also ,but i don't know where i am doing wrong. Whenever i click on the submit button it says there is no data.

//In Activity1
 public void saveInfo(View view){
        SharedPreferences sharedPref = getSharedPreferences("MyData", Context.MODE_PRIVATE);

        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putString("ques1",sa1.toString());
        editor.commit();
        Toast.makeText(this, "Saved!!", Toast.LENGTH_SHORT).show();






//In Activity3
//shared preferencess
    public void load(View view){
        SharedPreferences sharedPreferences = getSharedPreferences("MyData", Context.MODE_PRIVATE);
        String q1 = sharedPreferences.getString("ques1",DEFAULT);

        Toast.makeText(ActivitySix.this, "q1 : " + sharedPreferences.getString("ques1",DEFAULT), 1000).show();


        if (q1.equals(DEFAULT))
            Toast.makeText(this, "No data found", Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(this, "Data loaded sucessfully", Toast.LENGTH_SHORT).show();

    }
hk77798
  • 25
  • 1
  • 9

1 Answers1

-1

In first activity check your data is saved or not? Have you applied editor.commit() while saving your data onSharedPreference

Fazal Hussain
  • 1,129
  • 12
  • 28