In Android Studio, I have an activity that calls a view. The user clicks the view, the view continues for sometime, then finishes and sets public boolean finished = true.
Here is the activity that calls the view and its code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myView = new GameLevelView(this);
setContentView(myView);
}
In the view, I have this execute:
protected void onDraw(Canvas canvas) {
//Update canvas elements
if(cerainCondition == true){
finished = true;
}
try {
Thread.sleep(10); // Delay
} catch (InterruptedException e) { }
invalidate(); // Force a re-draw
}
This essentially keeps looping. However, I want the original activity to know that this view has set finished = true so that I can start another activity. I do not want to destroy the view because the other activity will be displayed on top.
How would I go about letting the activity know that the view has changed a variable?
I have considered BroadcastReceiver, but I see no way to actually set a broadcast, so I'm not sure if this would work.