2017-12-11 18 views
1

Android Studio를 사용하고 있습니다.부팅시 실행되는 디버그 앱

수신인이 android.intent.action.BOOT_COMPLETED를 수신하는 앱용 BroadcastReceiver를 추가 한 경우 수신자는 테스트 용 토스트 만 표시합니다. 문제는 안드로이드가 시작된 직후에 "App has stopped"이라는 메시지가 나타납니다.

내 첫 번째 질문은 : 어쨌든 시작할 때 디버깅하고 어디에서 문제가 있는지 확인하는 것입니까? Android Studio에서 해당 문제를 언급하는 로그를 볼 수 없기 때문입니다.

두 번째 질문은 문제 자체와 관련이 있습니다. 여기 코드는 다음과 같습니다 XML :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="myapp"> 

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity android:name="MainActivity"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <receiver 
      android:name=".AutoStartReceiver" 
      android:enabled="true"> 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      </intent-filter> 
     </receiver> 

    </application> 

</manifest> 

자바 : 브로드 캐스트 리시버

public class AutoStartReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Toast.makeText(context, "loaded", Toast.LENGTH_LONG).show(); 
     throw new UnsupportedOperationException("Not yet implemented"); 
    } 
} 

세 번째 질문 : 그것은 OK 수신기의 일부 무거운 작업합니다 (알람 관리기를 일부 파일을 읽고 설정)을 수행하는 서비스를 만드는 것보다? API 26에서 Android는 서비스에 많은 제약을 가하고 있기 때문입니다.

당신에게 두 번째 장치는 대개 자체가 부팅 할 응용 프로그램 전에 발생 디버깅 연결을 가져옵니다 디버깅 할 수 부팅 시작

답변

3

앱을 감사드립니다. 그냥 logcat을 열고 재부팅 후 장치 및 응용 프로그램이 팝업되는지 주시하십시오. 앱이 디버그 가능하다고 가정합니다. 그렇지 않은 앱은 단순히 로그를 표시하지 않습니다.

당신이 코드의 명백한 이유로 MyApp has unfortunately stopped 메시지가 :

public class AutoStartReceiver extends BroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Toast.makeText(context, "loaded", Toast.LENGTH_LONG).show(); 
     throw new UnsupportedOperationException("Not yet implemented"); 
    } 
} 

당신은 중단됩니다 의미 예외를 throw합니다. 당신이 오래가 RAM 및 프로세서의 합리적인 시간 내에 사용하기 때문에 당신이

을 갈 수 있어요 (매우 무거운 서비스는 배터리와 메모리를 절약하기 위해 죽을 가능성이 더 높습니다) 서비스에서하는 일에 관해서는

(에뮬레이터에있는 터미널에서) 나는이 사용하는 디버깅의 경우

+0

, 즉 그 것이었다. Android 시작시로드 될 때 로그가 비어 있지만 앱 로그를 가져올 수 없습니다. – hiddeneyes02