如果我在服务类中内联了一个计时器任务,并且Service类有一个公共方法..我如何从TimerTask中调用服务类中的公共方法?
class uiCheckTask extends TimerTask {
Boolean secDialog = false;
NavOverrideService myService;
public void run() {
try {
ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> processList = am.getRunningAppProcesses();
String cProcess = processList.get(0).processName;
if (!cProcess.equals("com.example.services_test") && !secDialog) {
// myService.launchSecurity(); /// HELP HERE!
} else {
}
} catch(Exception ex) {
}
}
}
launchSecuity:
public void launchSecurity(){
Log.v("LAUNCHING", "((((((((((((((((((((SECURITY)))))))))))))))))");
Intent intent = new Intent(this, SecurityService.class);
startService(intent);
}
答案 0 :(得分:1)
如果uiCheckTask
是您Service
的内部类,那么您可以通过
(MyService.this).launchSecurity()
请注意MyService
是您服务的类名,而不是实例或本地变量。