开发者

How come the preferences activity is launched when selecting my app from the menu displayed when pressing the Home button?

Steps:

  1. I start my Android app.
  2. I press the Menu button and select Preferences => preferences screen appears.
  3. I make a preference and then press the Back button => the application's main activity appears again.
  4. I press the Back buttton => Home screen.
  5. 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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜