我的应用程序由两个活动组成。在第一个活动中,从用户那里获取一些输入并通过意图传递给第二个活动。第二个活动启动两个IntentServices
来执行一些长时间运行的后台任务。我有一个停止服务的停止按钮。当我在停止服务后尝试按下后退按钮时,之前的活动会加载,但应用程序变得无响应并关闭。我试图通过查看此站点上的建议来解决问题,但问题仍然存在。
从第一个开始第二个活动的代码
Intent intent = new Intent(ConnectActivity.this, MessageActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.putExtra("ip", ip);
intent.putExtra("port", port);
intent.putExtra("tcpport", tcpport);
intent.putExtra("tcpip", tcpip);
intent.putExtra("packetType", PT);
startActivity(intent);
backButtonPressed()
来自第二个活动的代码
public void onBackPressed() {
if(UdpSendService.send)
while(!endTransmission());
//Intent intent = new Intent(this, ConnectActivity.class);
//intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
//startActivity(intent);
finish();
//super.onBackPressed();
}
endTransmission()
方法_
boolean endTransmission() {
UdpSendService.send=false;
if(receiver1!=null && receiver2!=null){
unregisterReceiver(receiver1);
unregisterReceiver(receiver2);
receiver1=null;
receiver2=null;
}
while(stopService(udpReceiveIntent)!=true);
System.out.println("\nreceive service stopped");
while(stopService(udpServiceIntent)!=true);
System.out.println("\nsend service stopped");
return true;
}
日志猫:
01-22 15:18:39.893: E/ActivityManager(162): ANR in com.example.udpmessageclient (com.example.udpmessageclient/.ConnectActivity)
01-22 15:18:39.893: E/ActivityManager(162): Reason: keyDispatchingTimedOut
01-22 15:18:39.893: E/ActivityManager(162): Load: 1.39 / 1.05 / 0.66
01-22 15:18:39.893: E/ActivityManager(162): CPU usage from 12723ms to 0ms ago:
01-22 15:18:39.893: E/ActivityManager(162): 63% 162/system_server: 53% user + 9.6% kernel / faults: 593 minor
01-22 15:18:39.893: E/ActivityManager(162): 35% 1467/com.example.udpmessageclient: 27% user + 7.9% kernel / faults: 44 minor
01-22 15:18:39.893: E/ActivityManager(162): 0.1% 293/com.android.phone: 0.1% user + 0% kernel / faults: 4 minor
01-22 15:18:39.893: E/ActivityManager(162): 99% TOTAL: 82% user + 17% kernel
01-22 15:18:39.893: E/ActivityManager(162): CPU usage from 3151ms to 3707ms later:
01-22 15:18:39.893: E/ActivityManager(162): 58% 162/system_server: 47% user + 10% kernel
01-22 15:18:39.893: E/ActivityManager(162): 9% 334/Binder_3: 9% user + 0% kernel
01-22 15:18:39.893: E/ActivityManager(162): 7.2% 173/Binder_1: 5.4% user + 1.8% kernel
01-22 15:18:39.893: E/ActivityManager(162): 7.2% 174/Binder_2: 7.2% user + 0% kernel
01-22 15:18:39.893: E/ActivityManager(162): 5.4% 162/system_server: 3.6% user + 1.8% kernel
01-22 15:18:39.893: E/ActivityManager(162): 5.4% 195/InputDispatcher: 1.8% user + 3.6% kernel
01-22 15:18:39.893: E/ActivityManager(162): 5.4% 336/Binder_4: 3.6% user + 1.8% kernel
01-22 15:18:39.893: E/ActivityManager(162): 5.4% 367/Binder_5: 5.4% user + 0% kernel
01-22 15:18:39.893: E/ActivityManager(162): 5.4% 374/Binder_6: 5.4% user + 0% kernel
01-22 15:18:39.893: E/ActivityManager(162): 5.4% 380/Binder_7: 3.6% user + 1.8% kernel
01-22 15:18:39.893: E/ActivityManager(162): 5.4% 383/Binder_8: 3.6% user + 1.8% kernel
01-22 15:18:39.893: E/ActivityManager(162): 39% 1467/com.example.udpmessageclient: 28% user + 10% kernel / faults: 2 minor
01-22 15:18:39.893: E/ActivityManager(162): 35% 1467/dpmessageclient: 25% user + 10% kernel
01-22 15:18:39.893: E/ActivityManager(162): 100% TOTAL: 78% user + 21% kernel
01-22 15:18:43.783: E/InputDispatcher(162): channel '4119ec38 com.example.udpmessageclient/com.example.udpmessageclient.ConnectActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
01-22 15:18:43.853: E/InputDispatcher(162): Received spurious receive callback for unknown input channel. fd=187, events=0x9
01-22 15:21:45.544: E/Trace(1523): error opening trace file: No such file or directory (2)
01-22 15:21:46.265: E/ActivityThread(278): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
01-22 15:21:46.265: E/BinaryDictionaryGetter(278): Could not find a dictionary pack
01-22 15:21:46.355: E/ActivityThread(278): Failed to find provider info for com.android.inputmethod.latin.dictionarypack
01-22 15:21:46.355: E/BinaryDictionaryGetter(278): Could not find a dictionary pack