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) {
}
}
}
launchSecuity:
public void launchSecurity(){
Log.v("LAUNCHING", "((((((((((((((((((((SECURITY)))))))))))))))))");
Intent intent = new Intent(this, SecurityService.class);
startService(intent);
}
實例化類並調用方法? –
我試過了,但我得到一個零點異常..該服務已經運行,並開始timerTask開始.. – erik
launchSecurity做什麼?它可以是靜態的嗎? – hBrent