0
나는이 코드를 사용하여 SMS를 전송하고 있습니다.브로드 캐스트 리시버가 언젠가 충돌합니다.
android.app.IntentReceiverLeaked: Activity com.example.senddemo.MainActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()?
12-23 15:23:32.800 E/ActivityThread(27024): at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:756)
12-23 15:23:32.800 E/ActivityThread(27024): at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:551)
12-23 15:23:32.800 E/ActivityThread(27024): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:836)
12-23 15:23:32.800 E/ActivityThread(27024): at android.app.ContextImpl.registerReceiver(ContextImpl.java:823)
12-23 15:23:32.800 E/ActivityThread(27024): at android.app.ContextImpl.registerReceiver(ContextImpl.java:817)
12-23 15:23:32.800 E/ActivityThread(27024): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:318)
12-23 15:23:32.800 E/ActivityThread(27024): at com.example.senddemo.MainActivity.sendSMS(MainActivity.java:331)
12-23 15:23:32.800 E/ActivityThread(27024): at com.example.senddemo.MainActivity.access$0(MainActivity.java:290)
12-23 15:23:32.800 E/ActivityThread(27024): at com.example.senddemo.MainActivity$2.onClick(MainActivity.java:120)
12-23 15:23:32.800 E/ActivityThread(27024): at android.view.View.performClick(View.java:2552)
12-23 15:23:32.800 E/ActivityThread(27024): at android.view.View$PerformClick.run(View.java:9229)
12-23 15:23:32.800 E/ActivityThread(27024): at android.os.Handler.handleCallback(Handler.java:587)
12-23 15:23:32.800 E/ActivityThread(27024): at android.os.Handler.dispatchMessage(Handler.java:92)
12-23 15:23:32.800 E/ActivityThread(27024): at android.os.Looper.loop(Looper.java:138)
12-23 15:23:32.800 E/ActivityThread(27024): at android.app.ActivityThread.main(ActivityThread.java:3701)
12-23 15:23:32.800 E/ActivityThread(27024): at java.lang.reflect.Method.invokeNative(Native Method)
12-23 15:23:32.800 E/ActivityThread(27024): at java.lang.reflect.Method.invoke(Method.java:507)
12-23 15:23:32.800 E/ActivityThread(27024): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
12-23 15:23:32.800 E/ActivityThread(27024): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
12-23 15:23:32.800 E/ActivityThread(27024): at dalvik.system.NativeStart.main(Native Method)
12-23 15:23:32.810 E/ActivityThread(27024): Activity com.example.senddemo.MainActivity has leaked IntentReceiver [email protected] that was originally registered here. Are you missing a call to unregisterReceiver()?
내가 내 xml 파일이나 내 OnDestry 기능에 무엇을 추가해야합니까 : 다른 시간이 전혀 오류 withour 정상적으로 재생되는 동안
private void sendSMS(String phoneNumber, String message) {
System.out.println("SMS: " + message);
System.out.println("to " + phoneNumber);
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(
SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
// ---when the SMS has been sent---
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
// ---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
// SmsManager sms = SmsManager.getDefault();
// sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
SmsManager sm = SmsManager.getDefault();
ArrayList<String> parts = sm.divideMessage(message);
int numParts = parts.size();
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
for (int i = 0; i < numParts; i++) {
sentIntents.add(sentPI);
deliveryIntents.add(deliveredPI);
}
sm.sendMultipartTextMessage(phoneNumber, null, parts, sentIntents,
deliveryIntents);
}
}
때때로이 오류는 무엇입니까? 나는 방송 수신기에 익숙하지 않기 때문에. 왜 때로는 다른 사람들은 연주하지 않습니까?