为什么我在拨打服务时收到此错误
E/ActivityManager(160): ANR in com.colo
E/ActivityManager(160): Reason: Executing service com.colo/.services.PmService
E/ActivityManager(160): Load: 8.41 / 7.12 / 6.4
E/ActivityManager(160): CPU usage from 21836ms to -1ms ago:
E/ActivityManager(160): 2.2% 160/system_server: 1.3% user + 0.9% kernel / faults: 9 minor
E/ActivityManager(160): 1.9% 65/bma_wq: 0% user + 1.9% kernel
E/ActivityManager(160): 1.4% 28646/com.colors.pipemedia: 1.2% user + 0.1% kernel / faults: 285 minor 1 major
E/ActivityManager(160): 0.5% 27859/com.google.android.apps.maps:NetworkLocationService: 0.4%
user + 0% kernel / faults: 280 minor 14 major
E/ActivityManager(160): 0.3% 18292/com.android.systemui: 0.3% user + 0% kernel / faults: 48 minor
E/ActivityManager(160): 0% 61/synaptics_wq: 0% user + 0% kernel
E/ActivityManager(160): 0.1% 144/adbd: 0% user + 0.1% kernel
E/ActivityManager(160): 0.1% 246/com.android.phone: 0.1% user + 0% kernel / faults: 1 minor
E/ActivityManager(160): 0% 62/check_ic_wq: 0% user + 0% kernel
E/ActivityManager(160): 0% 72/kondemand/0: 0% user + 0% kernel
E/ActivityManager(160): 0% 28602/logcat: 0% user + 0% kernel
E/ActivityManager(160): 0% 5/events/0: 0% user + 0% kernel
E/ActivityManager(160): 0% 58/file-storage: 0% user + 0% kernel
E/ActivityManager(160): 0% 90/rild: 0% user + 0% kernel
E/ActivityManager(160): 0% 237/com.hu1.wallpaper.forest: 0% user + 0% kernel / faults: 28 minor
E/ActivityManager(160): 0% 1276/com.google.process.gapps: 0% user + 0% kernel
E/ActivityManager(160): 0% 25919/flush-138:13: 0% user + 0% kernel
E/ActivityManager(160): 0% 26459/AR6K Async: 0% user + 0% kernel
E/ActivityManager(160): 0% 26461/ksdioirqd/mmc1: 0% user + 0% kernel
E/ActivityManager(160): 0% 26467/wpa_supplicant: 0% user + 0% kernel
E/ActivityManager(160): 0% 27702/com.wssyncmldm: 0% user + 0% kernel / faults: 9 inor
E/ActivityManager(160): 0% 28103/com.android.vending: 0% user + 0% kernel / faults: 1 minor
E/ActivityManager(160): 4.1% TOTAL: 2.8% user + 1.2% kernel
E/ActivityManager(160): CPU usage from 1156ms to 1691ms later:
E/ActivityManager(160): 43% 28646/com.colors.pipemedia: 31% user + 12% kernel / ults: 729 minor 2 major
E/ActivityManager(160): 14% 28649/GC: 12% user + 1.7% kernel
E/ActivityManager(160): 8.7% 28646/olors.pipemedia: 3.5% user + 5.2% kernel
E/ActivityManager(160): 5.2% 28652/Compiler: 3.5% user + 1.7% kernel
E/ActivityManager(160): +0% 28674/Thread-28: 0% user + 0% kernel
E/ActivityManager(160): +0% 28675/RefQueueWorker@: 0% user + 0% kernel
E/ActivityManager(160): 10% 160/system_server: 3.5% user + 7.1% kernel / faults: 4 minor
E/ActivityManager(160): 10% 176/ActivityManager: 3.5% user + 7.1% kernel
E/ActivityManager(160): 0.6% 22/kswapd0: 0% user + 0.6% kernel
E/ActivityManager(160): 1.8% 65/bma_wq: 0% user + 1.8% kernel
E/ActivityManager(160): 0.7% 72/kondemand/0: 0% user + 0.7% kernel
E/ActivityManager(160): 0.8% 26461/ksdioirqd/mmc1: 0% user + 0.8% kernel
E/ActivityManager(160): 1% 28602/logcat: 1% user + 0% kernel
E/ActivityManager(160): 83% TOTAL: 35% user + 20% kernel + 26% iowait
E/(160): Dumpstate > /data/log/dumpstate_app_anr
我点击按钮点击这样的服务。
final Intent pm_intent = new Intent(AccountsActivity.this , PmService.class);
pm_intent.putExtra("Key", "gtalk service*****");
pm_intent.putExtra("user_name", acc.getAcc_Name());
pm_intent.putExtra("user_pass", acc.getAcc_Pass());
Thread t = new Thread(){
public void run(){
startService(pm_intent);
}
};
t.start();
我在按钮点击
上停止这样的服务final Intent gtalk_intent = new Intent(getActivity() , GtalkService.class);
Thread t = new Thread(){
public void run(){
getActivity().stopService(gtalk_intent);
}
};
t.start();
答案 0 :(得分:6)
你得到一个ANR,所以你在UI线程上做了一些处理器密集型工作。
我发现您在新的Service
中启动了Thread
。虽然这可能看起来Service
将以新的Thread
开头,但实际上并非如此。如果要在新线程中运行服务的内容,则必须在onStartCommnand()
或onCreate()
内的服务中创建新线程。试着这样做。