0

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?

Yoda
  • 17,363
  • 67
  • 204
  • 344

1 Answers1

0

TRY

@Override
public void onBackPressed() 
{
      android.os.Process.killProcess(android.os.Process.myPid());
}

this is the best solution I've tried.

And This is the same as above in that it instantly terminates the Linux process and all threads for the app:

@Override
    public void onBackPressed() 
    {
          System.exit(0);
    }
Sree
  • 3,136
  • 2
  • 31
  • 39