How fragment get context in Android?

You can use getActivity() , which returns the activity associated with a fragment. The activity is a context (since
Activity extends Context ). You can also override the onAttach() method of fragment:

public static class DummySectionFragment extends Fragment{
public void onAttach(Activity activity) {
    DBHelper = new DatabaseHelper(activity);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s