Skip to content
This repository was archived by the owner on Apr 30, 2019. It is now read-only.
This repository was archived by the owner on Apr 30, 2019. It is now read-only.

event from activity to fragment  #155

@ziahaqi

Description

@ziahaqi

i have a problem when send event from activity (with post/produce) to a fragment. the event will be taken from binded service if the activity recevied notification via brodcast receiver when the service received a message.
Activity{
private SMS sms;
...
@OverRide
protected void onCreate(@nullable Bundle savedInstanceState) {
...
smsFragment = new TransactionSMSFragment();
getSupportFragmentManager().beginTransaction().add(R.id.stack_container, smsFragment, RegisterServerListFragment.TAG).commit();
}

private BroadcastReceiver smsReceiver = new BroadcastReceiver() {
....
@OverRide
public void onReceive(Context context, Intent intent) {
if(DEBUG)Log.i(TAG, "sms>reciver");
if(intent != null){
SMS sms = smsService.getReceivedMessege();
this.sms = sms;
EventBus.getInstance().post(sms);
}
}
};
@produce
public String produce(){
return this.sms;
}

  • the otto register on create and unregistered on destroy
  • and the fragment
    Fragment{
    ...
    @subscribe
    public void subscribeSMS(SMS sms){
    Log.d("bus", "sms:" + sms );
    }
    }

what wrong with those code ? how actually otto work ? thank's

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions