我想让有限状态机每5秒调用一次StartEstablishService()
方法,以便应用程序在服务失败后尝试重新连接到服务。当服务失败时,它将销毁服务,我唯一需要做的就是再次调用StartEstablishService()
方法,这是连接失败后的输出:Destroying service...Service destroyed
@Override
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "Destroying service...");
t.interrupt();
Log.d(TAG, "Service destroyed.");
}
如何每5秒拨打StartEstablishService()
一次?我在服务销毁后尝试调用以下方法
public void startExploring() {
Log.e(TAG,"Start Exploring Every 8 Seconds...");
final int FIVE_SECONDS = 5000;
final MainActivity activity = (MainActivity) getActivity();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
activity.startData();
handler.postDelayed(this,
FIVE_SECONDS);
}
}, 5000);
但它的活动总是为空?