안드로이드 개발 질문/답변
(글 수 45,052)
12-26 11:38:30.678: E/ActivityThread(278): Activity com.example.gcmmanager.MainActivity has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@43e4a3d0 that was originally registered here. Are you missing a call to unregisterReceiver()?
12-26 11:38:30.678: E/ActivityThread(278): android.app.IntentReceiverLeaked: Activity com.example.gcmmanager.MainActivity has leaked IntentReceiver com.google.android.gcm.GCMBroadcastReceiver@43e4a3d0 that was originally registered here. Are you missing a call to unregisterReceiver()?
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:939)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:734)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:791)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ContextImpl.registerReceiver(ContextImpl.java:778)
12-26 11:38:30.678: E/ActivityThread(278): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:325)
12-26 11:38:30.678: E/ActivityThread(278): at com.google.android.gcm.GCMRegistrar.setRetryBroadcastReceiver(GCMRegistrar.java:276)
12-26 11:38:30.678: E/ActivityThread(278): at com.google.android.gcm.GCMRegistrar.register(GCMRegistrar.java:202)
12-26 11:38:30.678: E/ActivityThread(278): at com.example.gcmmanager.MainActivity.onCreate(MainActivity.java:36)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-26 11:38:30.678: E/ActivityThread(278): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 11:38:30.678: E/ActivityThread(278): at android.os.Looper.loop(Looper.java:123)
12-26 11:38:30.678: E/ActivityThread(278): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-26 11:38:30.678: E/ActivityThread(278): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 11:38:30.678: E/ActivityThread(278): at java.lang.reflect.Method.invoke(Method.java:521)
12-26 11:38:30.678: E/ActivityThread(278): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-26 11:38:30.678: E/ActivityThread(278): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-26 11:38:30.678: E/ActivityThread(278): at dalvik.system.NativeStart.main(Native Method)
--- 보면은
unregisterReceiver 가 없다, 만들어달라. 이거 같은데
소스 보여드리겠습니다
# Intent 소스
----------
package com.example.gcmmanager;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gcm.GCMBaseIntentService;
public class GCMIntentService extends GCMBaseIntentService {
private static final String TAG = "GCM";
private static final String INSERT_PAGE = "http://itpam.kr/gcm/insert_registration.php";
private static final String SENDER_ID = "151962063888";
private GCMHttpConnect httpConnect = null;
private GCMHttpConnect.Request httpRequest = new GCMHttpConnect.Request() {
@Override
public void OnComplete() {
// TODO Auto-generated method stub
showToast();
}
};
public GCMIntentService() {
super(SENDER_ID);
}
@Override
protected void onMessage(Context context, Intent intent) {
if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE")) {
showMessage(context, intent);
}
}
@Override
protected void onError(Context context, String msg) {
// TODO Auto-generated method stub
Log.w(TAG, "onError!! " + msg);
}
/* @Override
protected void onRegistered(Context context, String regID) {
// TODO Auto-generated method stub
if(!regID.equals("") || regID != null){
Log.w(TAG, "onRegistered!! " + regID);
// 단일전송일때 주석처리
// insertRegistrationID(regID);
}
}
@Override
protected void onUnregistered(Context context, String regID) {
// TODO Auto-generated method stub
Log.w(TAG, "onUnregistered!! " + regID);
}
*/
// 기기 등록 후 호출
@Override
protected void onRegistered(Context context, String regId) {
// 기기 등록 성공
final String mID = regId;
//MainActivity.mHandler.post(new Runnable() {
Log.v("GCMIntentService", "onRegistered - " + regId);
}
// 기기 등록 해제 후 호출
@Override
protected void onUnregistered(Context context, String regId) {
Log.v("GCMIntentService", "onUnregistered - " + regId);
}
public void showToast(){
Toast.makeText(this, "RegID 등록 완료", Toast.LENGTH_LONG).show();
}
private void showMessage(Context context, Intent intent){
String title = intent.getStringExtra("title");
String msg = intent.getStringExtra("msg");
String ticker = intent.getStringExtra("ticker");
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Activity.NOTIFICATION_SERVICE);
// 해당 어플을 실행하는 이벤트를 하고싶을 때 아래 주석을 풀어주세요
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
// new Intent(context, 어플이 처음 시작되는 클래스명.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
Notification notification = new Notification();
notification.icon = R.drawable.ic_launcher;
notification.tickerText = ticker;
notification.when = System.currentTimeMillis();
notification.vibrate = new long[] { 500, 100, 500, 100 };
notification.sound = Uri.parse("/system/media/audio/notifications/20_Cloud.ogg");
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, title, msg, pendingIntent);
notificationManager.notify(0, notification);
}
public void insertRegistrationID(String id){
httpConnect = new GCMHttpConnect(INSERT_PAGE + "?regID=" + id, httpRequest);
httpConnect.start();
}
}
제 생각으로는 현재 만드신 코드가 실제로 리시버등록이 되어있는지를 먼저 확인하셔야 할 것으로 보입니다.
위 로그에서 말씀하시는 부분이 언레지스터 부분을 가리키고 있는 것은 맞는데요. 메인 엑티비티에서 가리키고 있는것으로 보아 GCMBaseIntentService를 상속받아 만드는 현재 코드 부분이 리시버에 등록이 되어야 하거나 (Manifast 파일에) 그게 아니라면 클래스 객체를 유지하여야 하는데 유지하지 못하여 생기는 오류로 보입니다.
개인적으로 GCM 을 코딩해 본적이 아직 없어서 확신은 못하겠습니다만 아마 그러하리라 예상합니다.