Im currently trying to develop a little game where i want to use a class that extends SurfaceView and have it to draw in i thread (similar to LunarLander). However when i would like to change contentview to the one from xml, the one im not drawing in i was trying to call a method from my surfaceview class that is in activity class that will change contentview by setContentView, i get an RuntimeException:
"Can't create handler inside thread that has not called Looper.prepare()"
It’s probably just because im somehow new to android and java development but i don’t understand why it will work when the method is a static method but not otherwise?
(method in my Start class that extends activity)
public void simulationDone()
{
.....
}
(trying to access it)
new Start().simulationDone();
A couple of problems:
First, you shouldn’t call
setContentViewmultiple times.Second, your surface view will need a reference to your activity. I tend to define listeners on my views that need to communicate back with an activity. In a custom
SurfaceViewcalledMySurfaceView:Then have your activity implement
MySurfaceView.Listenerand callmySurfaceView.setListener(this)when you create your surface view.