Screen dims and requires extra back button press after returning from PreferenceActivity
I've added a simple PreferenceActivity to my app, accessible through a context menu button. I can access the PreferenceActivity fine, and everything there works. The issue is when you leave the PreferenceActivity via the back button. The app's main activity reappears, but then the entire screen dims down, almost like there is a dialog that popped up or the context 开发者_运维知识库menu never disappeared, but there isn't. You cannot interact with the ListActivity that is in the background without pressing the back button or menu button.
Anybody have any ideas as to why this would happen?
Main Activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// get the inflater
MenuInflater inflater = getMenuInflater();
// inflate
inflater.inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection;
switch(item.getItemId()) {
case R.id.refresh:
refresh();
return true;
case R.id.subreddits:
startActivity(new Intent(this, Prefs.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
PreferenceActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.subreddit_preferences);
}
I wouldn't write the onCreateOptionsMenu()
that way. Instead of calling super
first and then returning true
, return the results of the chain to the superclass.
If that does not help, here is a sample project that uses a PreferenceActivity
and does not suffer from the problems you cite. See if you can deduce where your code differs from what I have.
I had the same issue, and my problem was that I had put a sub-menu under my "Settings" menu item.
Removing it fixed the issue.
精彩评论