开发者

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

开发者 https://www.devze.com 2023-02-02 15:20 出处:网络
Steps: I start my Android app. I press the Menu button and select Preferences => preferences screen appears.

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

精彩评论

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

关注公众号