私のアプリは 2 つのアクティビティで構成されています。最初のアクティビティでは、ユーザーから何らかの入力が取得され、インテントを通じて 2 番目のアクティビティに渡されます。2 番目のアクティビティはIntentServices
、実行時間の長いバックグラウンド タスクを実行するために 2 つを開始します。サービスを停止する停止ボタンがあります。サービスを停止した後に戻るボタンを押そうとすると、前のアクティビティが読み込まれますが、アプリが応答しなくなり、終了します。このサイトの提案を調べて問題を解決しようとしましたが、それでも問題は解決しません。
1st から 2nd アクティビティを開始するためのコード
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()
2番目のアクティビティからのコード
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