-1

I have an application where I check if User has GPS and Wireless Location enabled on device or not.If it's not enable then I startActivity to enable them .My code for this is:

if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
                || !locationManager
                        .isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.gps_not_found_title);  // GPS not found
            builder.setMessage(R.string.gps_not_found_message); // Want to enable?
            builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int i) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }
            });
            builder.setNegativeButton("Cancel", null);
            builder.create().show();
            return;
        }

The above code then start My Location activity for user to enable GPS and wireless location.After that If I press back button, it should go back to my application activity but it shows android launcher.I have also check Logs for any memory leak or any other problem for which it not returning to my application,but their is no such error.

Please help me.

Thanks In Advance

Ansh
  • 2,366
  • 3
  • 31
  • 51

2 Answers2

0

Use like this.

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.cancel();
            }
            });

        alertDialog.show();

For back button press,

WebView wt;//i used and given example by using webview               

    @Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if(event.getAction() == KeyEvent.ACTION_DOWN){
        switch(keyCode)
        {
        case KeyEvent.KEYCODE_BACK:
            if(wt.canGoBack() == true){
                wt.goBack();
            }
            else{
                this.finish();
            }

            return true;
        }

    }
    return super.onKeyDown(keyCode, event);
}
Shadow
  • 6,864
  • 6
  • 44
  • 93
0

I found my problem answer, I had android:noHistory="true" in my manifest file for activity.

Ansh
  • 2,366
  • 3
  • 31
  • 51