How come the preferences activity is launched when selecting my app from the menu displayed when pressing the Home button?
Steps:
- I start my Android app.
- I press the Menu button and select Preferences => preferences screen appears.
- I make a preference and then press the Back button => the application's main activity appears again.
- I press the Back buttton => Home screen.
- I press the Home button and select my app => Preferences screen appears...why??
Main activity
@Over开发者_Go百科ride
protected void onResume()
{
startService();
super.onResume();
}
private void startService()
{
...
preferences = PreferenceManager.getDefaultSharedPreferences(this);
startService(new Intent(MainActivity.this, WeatherService.class));
...
}
@Override
protected void onPause()
{
unbindService();
super.onPause();
}
private void onPreferences()
{
Intent i = new Intent(MainActivity.this, Preferences.class);
startActivity(i);
}
Preference activity
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
Cheers, Christian
you should have used "singleInstance" as activity launch mode. If so, try to set it as "SingleTask".
精彩评论