Android用EventBus Libraryの絶対基本実装を実装しようとしています。
ユーザーによる入力コンテンツを単純化しようとしているものとactivity 1
、インテント エクストラの代わりに、イベントバスを使用してオブジェクト全体を次のアクティビティに投稿していますactivity 2
。私は与えられたガイドラインに正確に従っています:
パート 1: ポジョ
public class StudentEvent {
public final String registrationNumber ;
public final String name ;
public final String course ;
public final String branch ;
public StudentEvent(String registrationNumber, String name, String course, String branch) {
this.registrationNumber = registrationNumber;
this.name = name;
this.course = course;
this.branch = branch;
}
public String getRegistrationNumber() {
return registrationNumber;
}
public String getName() {
return name;
}
public String getCourse() {
return course;
}
public String getBranch() {
return branch;
}
}
パート 2: 2 番目のアクティビティでのサブスクリプション
EventBus.getDefault().register(this); //onCreate
EventBus.getDefault().unregister(this); //onDestroy
@Subscribe
public void eventReceiver(StudentEvent studentEvent){
tvRegistrationNumber.setText(studentEvent.getRegistrationNumber());
tvName.setText(studentEvent.getName());
tvBranch.setText(studentEvent.getBranch());
tvCourse.setText(studentEvent.getCourse());
}
パート 3: イベントを投稿する
StudentEvent studentEventObject = new StudentEvent(
etRegistrationNumber.getText().toString(),
etName.getText().toString(),
etCourse.getText().toString(),
etBranch.getText().toString()) ;
EventBus.getDefault().post(studentEventObject);
エラーが表示されます:
D/EventBus: No subscribers registered for event class co.swisdev.abhinav.eventbustesting.StudentEvent
D/EventBus: No subscribers registered for event class org.greenrobot.eventbus.SubscriberExceptionEvent
何が足りないの?
同じクラスでサブスクリプションを作成すると機能します。