0

My goal is to give a parameter from Activity B to Activity A by using broadcastreceiver, it worked well. But when i tried to change the Fragment in Activity A from broadcast receiver, it showed "Can not perform this action after onSaveInstanceState"

here's my code :

Activity B

val myintentdata = Intent("message_subject_intent")
            myintentdata.putExtra("imagefile", file.path)
            LocalBroadcastManager.getInstance(this@IdentitasActivity).sendBroadcast(myintentdata)
            finish()

Activity A

val mMessageReceiver: BroadcastReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent) {
            if(intent.hasExtra("penghuni")){
                val name = intent.getStringExtra("penghuni")
                Toast.makeText(this@NeinActivity, name, Toast.LENGTH_SHORT).show()
            }else if(intent.hasExtra("imagefile")){
                val name = intent.getStringExtra("imagefile")
                Toast.makeText(this@NeinActivity, name, Toast.LENGTH_SHORT).show()
                Glide.with(this@NeinActivity).load(name).into(identitas)
                supportFragmentManager.beginTransaction().replace(R.id.frame_layout, FragmentSelesai()).commit();
            }
        }
    }
    LocalBroadcastManager.getInstance(this)
        .registerReceiver(mMessageReceiver, IntentFilter("message_subject_intent"))

All help means a lot to me.

anddev_riky
  • 1
  • 1
  • 3

1 Answers1

0

Answer Found

I've changed the code from

.commit()

to

.commitAllowingStateLoss()

more information in here :

https://stackoverflow.com/a/17527246/11306547

anddev_riky
  • 1
  • 1
  • 3