1

为什么我在调用服务时收到此错误

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();
4

1 回答 1

6

你得到一个 ANR,所以你在你的 UI 线程上做一些处理器密集型的工作。

我看到你正在推出Service一个新的Thread. 虽然这看起来像是Service会从一个新的开始Thread,但实际上并非如此。如果要在新的 Thread 中运行服务的内容,则必须在 Service 中创建新的 Thread,在onStartCommnand()或中onCreate()。尝试这样做。

于 2013-02-20T13:51:29.517 回答