0

I have my main depotactivity where he sets integer value to a textview, now I want this value to get updated when onResume() is called... but when I add my little onResume() code

public class DepotActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        DepotDBUtils utils = new DepotDBUtils(this);
        int itemcount = utils.countItems(this);

        TextView tv = (TextView)findViewById(R.id.counter);
        tv.setText(tv.getText()+" "+itemcount);
    }
   String TAG = "DepotActivity";
   String[] itemInfo;
 public void onResume(){
    Log.d("DepotActivity","onResume() gets called");
    DepotDBUtils utils = new DepotDBUtils(this);
    int itemcount = utils.countItems(this);

    TextView tv = (TextView)findViewById(R.id.counter);
    tv.setText(tv.getText()+" "+itemcount);
    } 

to the app I can't even start it, and LogCat gets totally crazy and doesn't log any activity for more than half a second. Any solutions? Thanks in advance

Aeefire
  • 89
  • 2
  • 11
  • 1
    Notice that onResume gets called even the first time the Activity is created, so there is no need to copy the code in onCreate and onResume. – aromero Jul 31 '11 at 15:48

1 Answers1

2

I'd start with adding super.onResume();:

@Override
protected void onResume(){
    super.onResume();
    // The rest
}

I would also remove that:

    DepotDBUtils utils = new DepotDBUtils(this);
    int itemcount = utils.countItems(this);

    TextView tv = (TextView)findViewById(R.id.counter);
    tv.setText(tv.getText()+" "+itemcount);

from onCreate, since every time onCreate is called, onResume is called as well.

MByD
  • 135,866
  • 28
  • 264
  • 277
  • 1
    Also add `@Override` to `onRexume()` and change from `public` to `protected` – Squonk Jul 31 '11 at 15:50
  • Thanks! ( I can only accept your answer in 3 minutes.. dunno why, but I'll do it) Thanks too for the additional tipp, cleaning up my code now :) and taking a second look at the android lifecycle lol – Aeefire Jul 31 '11 at 15:55