0

如果我在服务类中有一个内联的计时器任务,并且服务类有一个公共方法。我如何从 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) {

            }
        }
    }

启动安全:

public void launchSecurity(){
    Log.v("LAUNCHING", "((((((((((((((((((((SECURITY)))))))))))))))))");
    Intent intent = new Intent(this, SecurityService.class);
    startService(intent);
}
4

1 回答 1

1

如果uiCheckTask是你的内部类Service,那么你可以通过调用公共方法

(MyService.this).launchSecurity()

请注意,这MyService是您的服务的类名,而不是实例或局部变量。

于 2012-10-23T20:48:38.110 回答