Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jhwsx opened this issue Sep 3, 2018 · 0 comments
Open

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

jhwsx opened this issue Sep 3, 2018 · 0 comments

Comments

@jhwsx
Copy link

jhwsx commented Sep 3, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant