How to write context in Fragment

Asked 2 years ago, Updated 2 years ago, 67 views

I'd like to get a context from Fragment. I tried getApplicationContext() and FragmentClass.this to get a context from the database creator, but it didn't work. What should I do?

public Database(Context ctx) 
{
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
}

This is my code.

android android-fragments android-context

2022-09-21 17:38

1 Answers

If you use getActivity() in Fragment, you can get activities This activity is Context.


2022-09-21 17:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.