alert dialoge disappears in android after next page call

Solutions on MaxInterview for alert dialoge disappears in android after next page call by the best coders in the world

showing results for - "alert dialoge disappears in android after next page call"
Kayna
21 Mar 2020
1public void OnClickNearMe(View view) {
2    LocationManager locManager = (LocationManager) getSystemService(LOCATION_SERVICE);
3    if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){   
4        createGpsDisabledAlert();   
5    } else {
6        getLocation();
7    }
8}
9
10private void getLocation() {
11    Location locationResult = null;
12    MyLocation myLocation = new MyLocation();
13    boolean locationEnabled = myLocation.getLocation(this, locationResult);
14
15    if (locationEnabled == true) {
16        locationResult = myLocation.getLocationResult();
17        showResultsScreen(locationResult);
18    } else {
19        Toast.makeText(this, R.string.noLoc, Toast.LENGTH_LONG).show();
20    }
21}
22
23private void createGpsDisabledAlert(){   
24    AlertDialog.Builder builder = new AlertDialog.Builder(this);   
25    builder.setMessage("Your GPS is disabled! Would you like to enable it?")   
26         .setCancelable(false)   
27        .setPositiveButton("Enable GPS",   
28             new DialogInterface.OnClickListener(){   
29              public void onClick(DialogInterface dialog, int id){
30                   showGpsOptions(); 
31                   getLocation();
32              }   
33         });   
34         builder.setNegativeButton("Do nothing",   
35              new DialogInterface.OnClickListener(){   
36              public void onClick(DialogInterface dialog, int id){   
37                   dialog.cancel(); 
38              }   
39         });   
40    AlertDialog alert = builder.create();
41    alert.show();
42    }  
43
44    private void showGpsOptions(){   
45            Intent gpsOptionsIntent = new Intent(   
46                    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);   
47           startActivity(gpsOptionsIntent);   
48    }  
49
50    private void showResultsScreen(Location locationResult){
51         Intent resultsIntent = new Intent(this, ResultScreenList.class); 
52           startActivity(resultsIntent);
53    }
54}