0

あるアクティビティから別のアクティビティにブロードキャスト受信を送信する際に問題があります..動作していません.私のコードは以下のとおりです..plsはそれを参照してください..

送信クラスは次のとおりです。

    public class SendBroadcast extends Activity {
public static String BROADCAST_ACTION = "com.unitedcoders.android.broadcasttest.SHOWTOAST";

/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        sendBroadcast();
        }

    });
}




  public void sendBroadcast(){

    Intent broadcast = new Intent();
    broadcast.setAction("com.unitedcoders.android.broadcasttest.SHOWTOAST");
    sendBroadcast(broadcast);
}

}

受信クラスは次のとおりです。

  public class ToastDisplay extends Activity {

private BroadcastReceiver receiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("asdasd","sdasdasd");
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), "%%%%%%%%%%%%received", Toast.LENGTH_SHORT).show();

    }
};

@Override
protected void onResume() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(SendBroadcast.BROADCAST_ACTION);
    registerReceiver(receiver, filter);

    super.onResume();
}

@Override
protected void onPause() {
    unregisterReceiver(receiver);
    super.onPause();
}

}

マニフェスト ファイルは ::::

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.unitedcoders.android.broadcasttest"
  android:versionCode="1"
  android:versionName="1.0">
 <uses-sdk android:minSdkVersion="4" />

  <application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".SendBroadcast"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity android:name=".ToastDisplay">

    <intent-filter>
        <action android:name="com.unitedcoders.android.broadcasttest.SHOWTOAST">  </action>
    </intent-filter>
  </activity>

  </application>
  </manifest>
4

1 に答える 1

1

レシーバーをマニフェストに登録していません :registered as

<receiver android:name="receiver">
<intent-filter>
<action
android:name="com.unitedcoders.android.broadcasttest.SHOWTOAST"/>
</intent-filter>
</receiver>
于 2012-04-24T10:51:34.907 に答える