-1

I use Bundle approach from this link:https://stackoverflow.com/a/21102881/2641960

but i faced with this error:

 -15 11:14:47.323    8558-8558/co.kssg.expertnote E/InputEventReceiver﹕      Exception dispatching input event.
 04-15 11:14:47.323    8558-8558/co.kssg.expertnote E/MessageQueue-JNI﹕      Exception in MessageQueue callback: handleReceiveCallback
 04-15 11:14:47.333    8558-8558/co.kssg.expertnote E/MessageQueue-JNI﹕      java.lang.IllegalStateException: Activity has been destroyed

Here is my Method to Send Bundle Data To Fragment:

public void sendDataToFragment (String data)
{
    Bundle bundle = new Bundle();
    MainActivity ac = new MainActivity();
    FragmentManager fManager = ac.getFragmentManager();
    FragmentTransaction transaction = fManager.beginTransaction();
    bundle.putString("message", data );
    DataFragment dataFragment = new DataFragment();
    dataFragment.setArguments(bundle);
    transaction.replace(R.id.sFLayout, dataFragment);
    transaction.commit();
}

this method is placed in a custom ImageView Class.

Thanks for help.

Community
  • 1
  • 1
Adnan
  • 814
  • 12
  • 38

1 Answers1

2

I think this MainActivity ac = new MainActivity(); is not working.

You should add a reference in the constructor of your ImageView Class like this :

public class ImageView {
    private Activity mainActivity;

    public void ImageView(Activity mainActivity) {
        this.mainActivity = mainActivity;
    }

    public void sendDataToFragment (String data){
        Bundle bundle = new Bundle();
        FragmentManager fManager = mainActivity.getFragmentManager();
        FragmentTransaction transaction = fManager.beginTransaction();
        bundle.putString("message", data );
        DataFragment dataFragment = new DataFragment();
        dataFragment.setArguments(bundle);
        transaction.replace(R.id.sFLayout, dataFragment);
        transaction.commit();
    }
}
Maxouille
  • 2,729
  • 2
  • 19
  • 42