In the MainActivity I have:
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
Which caused closing the application but after I added this class the application is still available by holding home button:
package com.example.smbp1;
import android.app.Application;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.Log;
public class MyApplication extends Application {
public static int backColorRGB = 0;
@Override
public void onCreate() {
super.onCreate();
Log.i("APLIKACJA", "MTK");
usePreferences();
}
public void usePreferences(){
SharedPreferences settings = getSharedPreferences(OptionListActivity.MY_PREFERENCES, MODE_WORLD_READABLE);
String fontColorAsString = settings.getString(getResources().getString(R.string.font_color), "0");
int fColorRGB = 0;
if (fontColorAsString.equals("RED"))
fColorRGB = Color.RED;
else if (fontColorAsString.equals("BLUE"))
fColorRGB = Color.BLUE;
else if (fontColorAsString.equals("GREEN"))
fColorRGB = Color.GREEN;
Log.i("TRY TO READ", "TRY TO READ");
//background;
String backColorAsString = settings.getString(getResources().getString(R.string.background_color), "0");
Log.i(getResources().getString(R.string.font_color), backColorAsString);
if (backColorAsString.equals("RED"))
backColorRGB = Color.RED;
else if (backColorAsString.equals("BLUE"))
backColorRGB = Color.BLUE;
else if (backColorAsString.equals("GREEN"))
backColorRGB = Color.GREEN;
}
}
and added to manifest:
<application
android:name="com.example.smbp1.MyApplication"....
After hitting back button the application does not shut down. How to make it work again?