마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

똑같은 앱인데 옛폰은 되고 최근 나온폰은 GC켜지고 token null 뜨네요

0 추천
안녕하세요! 반도의 흔한 고딩입니다!
제가 어떤 앱을 개발하고 있었는데요....
MainActivity에서 서비스를 추가하는 과정에서
 
갤노트10.1과 옵티머스 뷰(굉장히 옛날거)에서는 문제없이 실행되던 것이
갤럭시 알파와 옵티머스 Gpro(최근에 나온거)에서는 계속 실행 오류가 나며 먹히지 않습니다 ㅠㅠㅠㅠ
@Override
public void onClick(View v) {
    int view = v.getId();
    
    switch(view){
    case R.id.startServiceBtn :
        startWinklick();
        break;
    }
        
}
private void startWinklick(){
    startService(new Intent(this, ScreenService.class));    //화면 잠금여부 확인하는 서비스 시작
    startService(new Intent(this, FaceService.class));    //서비스 시작//token null is not for an application
    //WindowManager$BadTokenException: Unable to add window -- token null is not for an application
    
    if(ScreenReceiver.actionService == null) {
        ScreenReceiver.actionService = new Intent(getApplicationContext(), ActionService.class);
        ScreenReceiver.actionService.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startService(ScreenReceiver.actionService);//머신러닝과 커서를 담당하는 액션서비스 시작
    }//GC 켜진다. 이유 알아오자
    
    Intent intent = new Intent();
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.HOME");
    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS 
    | Intent.FLAG_ACTIVITY_FORWARD_RESULT
                | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP
                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    startActivity(intent);//홈키 누른것처럼
    
}

 

위의 소스코드는 갤노트10.1과 옵티머스 뷰에서는 되지만,
갤럭시 알파와 옵티머스 Gpro 에선 되지 않습니다
14~21번째 줄이 모두 에러사항인데요
 
 
갤럭시 알파에서는요,
14번째 줄은
WindowManager$BadTokenException: Unable to add window -- token null is not for an application
가 뜨고요,
17~21번째 줄은
GC(가비지 컬렉터)가 켜지면서 작동을 안합니다 ㅠㅠㅠㅠ
 
 
옵티머스 Gpro에서는요
14번째 줄은 
Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1) 가 뜨고요,
17~21번째 줄은
Performing stop of activity that is not resumed:
 
 
 
특히, 14번째 줄 token null is not for an application 에러는 구글링 해서 알아본 결과대로
startService(new Intent(this, FaceService.class));
startService(new Intent(MainActivity.this, FaceService.class));
startService(new Intent(getApplicationContext(), FaceService.class));
다 해봤는데도 셋 다 안되더라구요 ㅠㅠㅠ
 
분명히, 갤럭시 알파와 옵티머스 Gpro가
옵뷰나 갤놋10.1보단 훨씬 최근에 나온 핸드폰 인데,
왜  GC 켜지고 난리인지 모르겠습니다 ㅠㅠㅠㅠ
 
아래는 17~21번째줄 Screen Receiver 전문입니다
package me.blog.haj990108.winklick;
 
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
 
public class ScreenReceiver extends BroadcastReceiver{
    
    
    
    public static Intent unlockService, actionService; //static은 정적변수로 위치를 고정하므로 타 클래스와의 공유가 가능.
    
    @Override
    public void onReceive(Context context, Intent intent) {
        // 브로캐스트를 ScreenService를 통해 받으면 여기서 자동으로 리시버된 액션 실행
        // 다른 것과 다르게, ScreenService로 동적으로 브로캐스트리시버를 등록해야 함
        // IntentFilter를 추가하려면 ScreenService에서 두번 추가하세얀
        // 그래도 이건 매 작동시마다 처리해주니 서비스보다 여기에 액션을 넣는게 개이득
        
        
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {    //스크린이 꺼지면
            Log.i("TAG", "ScreenReceiver-ACTION_SCREEN_OFF");
            
            if(ScreenReceiver.actionService != null){
                context.stopService(actionService);
                actionService = null;
            }//잠금시 제거되고 잠금해제시 작동됨
            
            unlockService = new Intent(context, UnlockService.class);//인식2 실행
            unlockService.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //context.startActivity(i);
            context.startService(unlockService);
        }
        if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {    //스크린이 켜지면
            Log.i("TAG", "ScreenReceiver-ACTION_SCREEN_ON");
            
            context.stopService(unlockService);//인식2 종료
            if(ScreenReceiver.actionService == null) {
                actionService = new Intent(context, ActionService.class);//인식1 실행
                actionService.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startService(actionService);
            }
        }    
    }
    
}
 
답글 달아주시면 정말 감사드리겠습니다!!!
덧글 달아주시면 더 필요하신 정보를 알려드리겠습니다!!!!

 

레비튼 (320 포인트) 님이 2015년 6월 7일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...