I have an android app that draws to a canvas. Up to now I've been drawing each time I create the app usine onCreate as such:
package com.example.drawdemo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
public class DrawDemo extends Activity {
DrawView drawView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
}
}
However I'd like to migrate the drawing to onResume. Ideally I do not draw the first time someone starts the program, only when they resume the program. Why do the following two code snippets not work:?
package com.example.drawdemo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
public class DrawDemo extends Activity {
DrawView drawView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
}
@Override
public void onResume(){
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
}
}
and
package com.example.drawdemo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
public class DrawDemo extends Activity {
DrawView drawView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onResume(){
drawView = new DrawView(this);
drawView.setBackgroundColor(Color.WHITE);
setContentView(drawView);
}
}
Make sure you call super.onResume()
- your activity will not function properly without it.