From 6bdfe3f1b2673389ebfd636b0513cc8e89fa030a Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Mon, 30 Mar 2015 17:30:07 -0700 Subject: Fix fragments not having a context before onCreateOptionsMenu sometimes --- src/github/daneren2005/dsub/activity/SubsonicActivity.java | 1 + src/github/daneren2005/dsub/fragments/SubsonicFragment.java | 4 ++++ 2 files changed, 5 insertions(+) (limited to 'src/github/daneren2005') diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index d5821dac..5c355eaf 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -349,6 +349,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte menuInflater.inflate(R.menu.drawer_menu, menu); } else if(currentFragment != null) { try { + currentFragment.setContext(this); currentFragment.onCreateOptionsMenu(menu, menuInflater); } catch(Exception e) { Log.w(TAG, "Error on creating options menu", e); diff --git a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java index fcba86a2..1e2d2ad8 100644 --- a/src/github/daneren2005/dsub/fragments/SubsonicFragment.java +++ b/src/github/daneren2005/dsub/fragments/SubsonicFragment.java @@ -164,6 +164,10 @@ public class SubsonicFragment extends Fragment implements SwipeRefreshLayout.OnR context = (SubsonicActivity)activity; } + public void setContext(SubsonicActivity context) { + this.context = context; + } + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { -- cgit v1.2.3