内部クラス登録BroadcaseReceive

1040 ワード

public class BroadcastActivity_1 extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = new Intent();
		intent.setAction("AAAA");
		sendBroadcast(intent);
	}
}
public class BroadcastActivity_2 extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		System.out.println("xxx");
	}
	
	public static class MyBroadcastReceive extends BroadcastReceiver{
		@Override
		public void onReceive(Context context, Intent intent) {
			System.out.println(intent.getAction());
		}
	}
}

注意外部クラスと内部クラスは$で接続されています
 <receiver android:name="com.activity.BroadcastActivity_2$MyBroadcastReceive">
		      <intent-filter>
					<action android:name="AAAA"></action>		          
		      </intent-filter>      
        </receiver>