-2
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent fi = getIntent();
    if (fi.getExtras() != null) {
        Rating = fi.getStringExtra("KEY_rating");
        Toast.makeText(getApplicationContext(), "Thanks for giving us " + Rating + " stars", Toast.LENGTH_LONG).show();
    }
}

Code lower down.

public void onSaveInstanceState(Bundle savedInstanceState) {
    //save users values
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putDouble(SAVED_VALUE, dblInput);
}

I had an error on protected void onCreate(Bundle savedInstanceState) and public void onCreate(Bundle values) It is fixed now, This is the correct way of getting intents from another activity.

maDub
  • 69
  • 10

4 Answers4

3

The method onCreate is duplicated. I think that you are extending a class with protected void onCreate(Bundle savedInstanceState) method and a interface with public void onCreate(Bundle values) method.

If that is tha case, than you should put all your code with the apropriates modifications in the implementation with public visibility and delete the implementation with the protected visibility.

If not, choose the best visibility implementation and put all your code there, deleting de other one.

Fabrício Benvenutti
  • 3,556
  • 1
  • 9
  • 5
2

Method onCreate is duplicated.

Jaime A. García
  • 146
  • 1
  • 10
2

sorry, I don't follow :/ – martin drap

Try it:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent fi = getIntent();
    if (fi.getExtras() != null) {
        Rating = fi.getStringExtra("KEY_rating");
        Toast.makeText(getApplicationContext(), "Thanks for giving us " + Rating + " stars", Toast.LENGTH_LONG).show();
    }

    if (savedInstanceState != null){
        dblInput = savedInstanceState.getDouble("");
    }
}
Fabrício Benvenutti
  • 3,556
  • 1
  • 9
  • 5
  • that got rid of the error but I still cant get the saved instance to be shown in the editText on return from second activity – maDub Oct 23 '15 at 21:18
  • to solve this problem, try the post [How to pass the values from one activity to previous activity](http://stackoverflow.com/questions/1124548/how-to-pass-the-values-from-one-activity-to-previous-activity). – Fabrício Benvenutti Oct 24 '15 at 01:24
0

You cant have two method with same signature in a class : so rename one of them

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Intent fi = getIntent();
if (fi.getExtras() != null) {
    Rating = fi.getStringExtra("KEY_rating");
    Toast.makeText(getApplicationContext(), "Thanks for giving us " +
       Rating + " stars", Toast.LENGTH_LONG).show();
}


}
//@Override
public void onCreate_duplicate(Bundle values) {
if (values != null){
    dblInput = values.getDouble("");
}
}
  • I tried that before but I get an error that the method I renamed is never used – maDub Oct 23 '15 at 20:23
  • Method 'onCreate_duplicate(android.os.Bundle)' is never used – maDub Oct 23 '15 at 20:26
  • This is not an error, its a warning that your code contains something that no one needs (anymore). You can ignore that or delete the unused code. – Tom Oct 23 '15 at 20:45
  • I ran the app and the code doesn't work. maybe I have something wrong with this part? `public void onSaveInstanceState(Bundle values) { super.onSaveInstanceState(values); values.putDouble("", dblInput); }` – maDub Oct 23 '15 at 20:52