我的Android应用程序需要通过事件的序列,以状态机来运行状态机和意图
事件1:播放视频#1
事件2:加载图像,等待按下按钮
事件3:播放视频#2
等等
这样做将产生每个事件的独立活动的一种方式,但有超过20事件我认为有一个更简单的方法来做到这一点。
所以我编写了一个状态机这样的:
int mState = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//
switch(mState) {
case 0:
Boolean flag = videoIntent(url0);
break;
case 1:
flag = loadImage(img1);
}
}
public Boolean videoIntent(String video) {
mBundle.putString("url",video);
Intent myIntent = new Intent();
myIntent.putExtras(mBundle);
myIntent.setClass(mySM.this, SM_vPlayer.class);
startActivity(myIntent);
mState ++;
return true;
}
public Boolean loadImage(String image) {
//load image
mState ++;
return true;
}
问题:开始的意图播放视频(该活动有一个监听器,等待完成),然后结束()被调用后。
where finish()会回到onCreate,onResume或其他方法吗?
我该如何回到switch语句?
有没有更好的方法来做到这一点?