You are about to pass an instance of Activity
to Fragment
, and the newInstance
method:
public static DailyFragment newInstance (Activity activity) {
DailyFragment dailyFragment = new DailyFragment();
Bundle bundle=new Bundle();
bundle.putSerializable("activity", newObject[]{activity});
dailyFragment.setArguments(bundle);
return dailyFragment;
}
And when I restored Activity
, I did the following:
(Activity) getArguments().getSerializable("activity")
However, the error java.lang.Object[]cannot be cast to android.app.Activity
appears.
How can I save and use Activity
in newInstance
using putSerializable
?
Please let me know if anyone knows.I'm sorry, but I appreciate your cooperation.
Nice to meet you.
The contents of the error say that the array of objects cannot be cast in Activity.
I can't do this.Activity is only an object child.
Also, Activity does not implement Serializable itself, so get it from putSerializable
I don't think it's possible toParcelable is not implemented either.
What exactly do you want to save about Activity?
If you want to save the Activity state, you can use the bundle itself that you can retrieve in the onSaveInstanceState.
It can also be stored in a bundle.You can also put a bundle in the bundle.
I would appreciate it if you could refer to it.
serialize
Only classes that implement the Serializable
interface (implementations
) can be used.
The Activity
class does not implement the Serializable
interface and cannot be putSerializable
.
Even if Activity
implements Serializable
, it becomes a different instance when getSerializable
.
Why do I need an instance of Activity
?
Can't I do getActivity()
with Fragment
?
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.