2012-04-23 3 views
2

내 매니페스트 파일에 활동 및 브로드 캐스트 리시버를 선언했지만 별도의 공용 클래스로 내 활동에 onReceive() 코드가 있습니다. adb 명령 줄에서 브로드 캐스트를 트리거하려고하면 classnotfound 오류가 발생합니다.브로드 캐스트 리시버를 별도의 파일로 만들어야합니까?

제 질문은 broadcastreceiver을 별도의 파일로 별도의 클래스로 만들어야합니까?

 @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     ActivityAsDialogActivity.this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     : 
     : 
     } 
public class TestEmail extends BroadcastReceiver{ 
     @Override 
     public void onReceive(Context context, Intent intent) { 
      if (intent.getAction().equals(MYINTENT)){ 
        Log.d("Manju ==>","ActivityAsDialogActivity, Got the intent"+MYINTENT); 
        Toast.makeText(context, "Don't panik but your time is up!!!!.", 
          Toast.LENGTH_LONG).show(); 
      }//end of if statment 
     }//end of onReceiver 
    }//end of Broadcast 
}//end of class ActivityAsDialogActivity 

아래 매니페스트 파일을

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

    <uses-sdk android:minSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".ActivityAsDialogActivity" 
      android:excludeFromRecents="true" 
      android:theme="@style/EmptyActivity" 
      android:configChanges="keyboardHidden|orientation|screenSize|uiMode"> 
      <!-- android:theme="@android:style/Theme.Holo.Dialog" 
      android:label="@string/app_name" --> 

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

     <receiver android:name="com.mot.activityasdialog.ActivityAsDialogActivity.TestEmail" android:enabled="true"> 
      <intent-filter> 
       <action android:name="com.mot.MANJU"></action> 
      </intent-filter> 
     </receiver> 

    </application> 

</manifest> 
+0

그리고 그들이 그 (것)들에 대하여 논평 할 것을 돕지 않은 경우에. –

답변

1

짧은 대답 : 예는 다른 클래스해야합니다. 그리고 별도의 파일에.

답변 : 귀하의 BroadcastReceiver는 BroadcastReceiver의 서브 클래스 여야하며 Activity는 Activity의 하위 클래스 여야하며 Java는 다중 상속을 허용하지 않으므로 Activity와 BroadcastReceiver는 적절한 방식으로 관련되지 않습니다. 예, 두 가지 수업을 거쳐야합니다.

자체 파일에 있어야하는 것 같습니다. 나는 그것을 시도하고 시스템이 내부 클래스 인 경우 BroadcastReceiver를 찾을 수 없다. 공개 여부.

관련 문제