Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Activity context in Bundle

I am using static factory method to create fragment. But I need to use activity's context in the fragment and therefore I need to wrap that context into a bundle and attach it to the fragment using setArguements() method so that I can retrieve it later.

But if I try to store context by doing bundle.putSerializable("tag", context) -> it throws an error. Can anyone tell me how to wrap activity context into a bundle?

like image 707
allstraws Avatar asked Apr 15 '26 16:04

allstraws


1 Answers

But I need to use activity's context in the fragment

You do not need it in most cases. All you need is to use getActivity() in your fragment instead.

like image 80
Marcin Orlowski Avatar answered Apr 18 '26 07:04

Marcin Orlowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!