2017-02-06 1 views
1

シンプルなブロードキャストリスナーを使って遊んでいましたが、そこにはtextView.setText( "text")のようなことがあります。しかし、リスナーはかなり大きなものになり、私は別のクラスに入れました。 私はAAが好きです、私は分離されている私のBroadcastReceiverから現在の活動からのビューを管理し続けるだけです。私のような何かをするとき、しかし:Android Annotationを使用して私のBroadcastReceiverにActivityインスタンスを挿入するにはどうすればよいですか?

Error:(25, 2) error: org.androidannotations.annotations.RootContext can only be used in a class annotated with @org.androidannotations.annotations.EBean. 

私は上記@EBean追加しようとすると、私はさらに悪いことがあります:

Error:(27, 28) error: Something went wrong: Unexpected error in AndroidAnnotations 4.2.0! 
You should check if there is already an issue about it on https://github.com/androidannotations/androidannotations/search?q=java.lang.ClassCastException&type=Issues 
If none exists, please open a new one with the following content and tell us if you can reproduce it or not. Don't forget to give us as much information as you can (like parts of your code in failure). 

答えて

0

あなたがすることはできません

@EReceiver 
public class WarningActivityStateListener extends BroadcastReceiver { 
    @RootContext //or Bean 
    WarningActivity activity; 

私はエラーを持っていますそれはBroadcastReceiverContextが受信者自身であるため、Activityとは関係ありません。アプリケーションContext@Appアノテーションでのみ注入できます。

EDIT:あなたは@ReceiverであなたのActivityのメソッドに注釈を付けることができます

Intent sおよびBroadcastReceiver登録/登録解除受信処理します:

@EActivity 
public class MyActivity extends Activity { 

    @Receiver(actions = "org.androidannotations.ACTION_1") 
    protected void onAction1() { 
    // Will be called when an org.androidannotations.ACTION_1 intent is sent. 
    } 

} 

それとも通常のBroadcastReceiverを作成することができますが、 onReceiveメソッドからイベントバスまたはLocalBroadcastReceiverを経由してActivityにイベントを送信します。

+0

ありがとうございます。しかし、この場合にUIとやりとりする方法は? AAを使用する前に、私はWarningActivityを使ってコンストラクタを作成しました。アクティビティでは、 'private BroadcastReceiver stateReceiver = new WarningActivityStateListener(this);'のようになり、受信者では 'WarningActivityStateListener(WarningActivity activity){ \t \t this.activity = activity; \t} ' - アクティビティを使用してビューを変更することができます。 AAと交換する方法を教えてください。 – Eugene

+0

私はAppのIntentBuilderが助けてくれるかもしれないと思うが、わからない) – Eugene

+0

@Eugene私は答えを更新した。 – WonderCsabo

関連する問題