インテントに渡してブロードキャストリスナーから受信するためのパラメータとしてリストを追加したいのですが、何か問題があります。このリストを意図としてインテントに追加する方法や、そこからリストを取得する方法はわかりません。私は放送受信機に入ることができます。Wifiからのスキャン結果のリストをインテントに追加し、ブロードキャストレシーバーから取得しますか?
//In my Main File: Everthing is registered and working.
IntentFilter startUsingScanResults = new IntentFilter("StartUsingScanResults");
c.registerReceiver(serviceConsume.ScanResultReceiver, startUsingScanResults);
List<ScanResult> scanResults = Some values;
Intent intent = new Intent();
intent.setAction("StartUsingScanResults");
// Then Need to put the List<ScanResults> into the intent.
// ie: intent.putExtra("MyResults", scanResults);
Context.sendBroadcast(intent);
//リストが内部にあるはずの自分のブロードキャスト受信者。
public BroadcastReceiver ScanResultReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
// Need something here to get the list
// ie: List<ScanResult> scanResults = extras.getBundle("MyResults");
}
};
うまくいけば、私はこの質問ではっきりしています。リストを入れてバンドル(またはインテント)からリストを取得するだけです。
この場合、ScanResultは[""、 ""、 ""、 ""、 ""、 "" "]の形式になります。ですから多次元配列に似ているかもしれません。
ご協力いただきましてありがとうございます。ありがとう
ルック: [渡すのArrayListとparcelableアクティビティー] [1] [1]:http://stackoverflow.com/questions/5819238/help-with-passing- arraylist-and-parcelable-activity – motiver