Skip to content

Can we have a better way to get actvitiy instance in Fragment? #77

@jhwsx

Description

@jhwsx

hi,

I integrate this architecture in my code, but I have found that it is not a good way to keep the reference of a activity like the following:

   @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof BaseActivity) {
            BaseActivity activity = (BaseActivity) context;
            mActivity = activity;
            activity.onFragmentAttached();
        }
    }

Because the reference may be finished, destroyed, which is not valid for use. In fact, I have to check whether the activity is valid all the time. which I really feel bothered. Can we find a better way? Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions