App start when GPS is enabled crashes

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

App start when GPS is enabled crashes

Postby qubit » Thu Nov 04, 2010 12:47 am

Can anyone offer an insight into my problem please?

My app works when GPS is disabled, but FC's when starting while GPS is enabled. On a cold start it offers the option to turn on the GPS. After doing that, pressing the back arrow button it returns to the app activity (although the GPS icon is not visible in the status bar, on a side note, how do I get it to display here?).

I exit the application by pressing the back button or using the menu option whilst GPS is still on.
Now, when I try to start the app, it FC's. The blinking GPS icon appears behind the FC message and disappears when I acknowledge the FC.

Here is the code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.         /** Called when the activity is first created. */
  3.         public void onCreate(Bundle savedInstanceState) {
  4.                 super.onCreate(savedInstanceState);
  5.                 setContentView(R.layout.main);
  6.                 getLocation();
  7.                 setupWebView();
  8.                 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  9.         }
  10.  
  11.         private void setupWebView() {
  12.                 final String centerURL = "javascript:centerAt("
  13.                                 + mostRecentLocation.getLatitude() + ","
  14.                                 + mostRecentLocation.getLongitude() + ")";
  15.                 webView = (WebView) findViewById(R.id.webview);
  16.                 // Get rid of white line on the right
  17.                 webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
  18.                 webView.getSettings().setJavaScriptEnabled(true);
  19.                 // Wait for the page to load then send the location information
  20.                 webView.setWebViewClient(new WebViewClient() {
  21.                         @Override
  22.                         public void onPageFinished(WebView view, String url) {
  23.                                 webView.loadUrl(centerURL);
  24.                         }
  25.  
  26.                 });
  27.                 webView.loadUrl(MAP_URL);
  28.         }
  29.  
  30.         /**
  31.          * The Location Manager manages location providers. This code searches for
  32.          * the best provider of data (GPS, WiFi/cell phone tower lookup, some other
  33.          * mechanism) and finds the last known location.
  34.          **/
  35.         private void getLocation() {
  36.                 locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  37.                 if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
  38.                         createGpsDisabledAlert();
  39.                 }
  40.                 Criteria criteria = new Criteria();
  41.                 criteria.setAccuracy(Criteria.ACCURACY_FINE);
  42.                 provider = locationManager.getBestProvider(criteria, true);
  43.  
  44.                 // In order to make sure the device is getting location, request
  45.                 // updates.
  46.  
  47.                 // Look to tweaking the arguments to this for a smooth ride
  48.                 locationManager.requestLocationUpdates(provider, 1, 0, this);
  49.                 mostRecentLocation = locationManager.getLastKnownLocation(provider);
  50.         }
  51.  
  52.         private void createGpsDisabledAlert() {
  53.                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
  54.                 builder.setMessage("Your GPS is disabled! Would you like to enable it?")
  55.                                 .setCancelable(false)
  56.                                 .setPositiveButton("Enable GPS",
  57.                                                 new DialogInterface.OnClickListener() {
  58.                                                         public void onClick(DialogInterface dialog, int id) {
  59.                                                                 showGpsOptions();
  60.                                                         }
  61.                                                 });
  62.                 builder.setNegativeButton("Use Wifi or 3g for location",
  63.                                 new DialogInterface.OnClickListener() {
  64.                                         public void onClick(DialogInterface dialog, int id) {
  65.                                                 dialog.cancel();
  66.                                         }
  67.                                 });
  68.                 AlertDialog alert = builder.create();
  69.                 alert.show();
  70.         }
  71.  
  72.         private void showGpsOptions() {
  73.                 Intent gpsOptionsIntent = new Intent(
  74.                                 android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
  75.                 startActivity(gpsOptionsIntent);
  76.         }
  77.  
  78.         // Menu setup
  79.         @Override
  80.         public boolean onCreateOptionsMenu(Menu menu) {
  81.                 menu.add(0, 0, 0, R.string.close).setIcon(
  82.                                 android.R.drawable.ic_menu_close_clear_cancel);
  83.                 return super.onCreateOptionsMenu(menu);
  84.         }
  85.  
  86.         @Override
  87.         public boolean onOptionsItemSelected(MenuItem item) {
  88.                 switch (item.getItemId()) {
  89.                 case 0:
  90.                         super.onStop();
  91.                         super.onDestroy();
  92.                         this.finish();
  93.                         return true;
  94.                 default:
  95.                         return super.onOptionsItemSelected(item);
  96.                 }
  97.         }
  98.  
  99.         @Override
  100.         protected void onResume() {
  101.                 locationManager.requestLocationUpdates(provider, 1, 0, this);
  102.                 super.onResume();
  103.         }
  104.  
  105.         @Override
  106.         protected void onPause() {
  107.                 locationManager.removeUpdates(this);
  108.                 super.onPause();
  109.         }
  110.  
  111.         /** Sets the mostRecentLocation object to the current location of the device **/
  112.  
  113.         public void onLocationChanged(Location location) {
  114.                 mostRecentLocation = location;
  115.                 final String centerURL = "javascript:centerAt("
  116.                                 + mostRecentLocation.getLatitude() + ","
  117.                                 + mostRecentLocation.getLongitude() + ")";
  118.  
  119.                 // This line is good to update the map with the current location
  120.                 webView.loadUrl(centerURL);
  121.         }
  122.  
Parsed in 0.044 seconds, using GeSHi 1.0.8.4


and here is a logcat of the error:
Syntax: [ Download ] [ Hide ]
  1. D/AndroidRuntime( 3271):  
  2. D/AndroidRuntime( 3271): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 
  3. I/AndroidRuntime( 3271): Heap size: -Xmx16m 
  4. D/AndroidRuntime( 3271): CheckJNI is OFF 
  5. D/dalvikvm( 3271): creating instr width table 
  6. D/AndroidRuntime( 3271): --- registering native functions --- 
  7. D/AndroidRuntime( 3271): Shutting down VM 
  8. D/jdwp ( 3271): Got wake-up signal, bailing out of select 
  9. D/dalvikvm( 3271): Debugger has detached; object registry had 1 entries 
  10. I/AndroidRuntime( 3271): NOTE: attach of thread 'Binder Thread #3' failed 
  11. D/AndroidRuntime( 3280):  
  12. D/AndroidRuntime( 3280): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 
  13. I/AndroidRuntime( 3280): Heap size: -Xmx16m 
  14. D/AndroidRuntime( 3280): CheckJNI is OFF 
  15. D/dalvikvm( 3280): creating instr width table 
  16. D/AndroidRuntime( 3280): --- registering native functions --- 
  17. D/dalvikvm( 3249): GC_FOR_MALLOC freed 12641 objects / 1342080 bytes in 85ms 
  18. D/AndroidRuntime( 3280): Shutting down VM 
  19. D/alogcat ( 3249): stopping ... 
  20. D/alogcat ( 3249): paused 
  21. D/jdwp ( 3280): Got wake-up signal, bailing out of select 
  22. D/dalvikvm( 3280): Debugger has detached; object registry had 1 entries 
  23. I/AndroidRuntime( 3280): NOTE: attach of thread 'Binder Thread #3' failed 
  24. E/jdwp ( 3288): Failed sending reply to debugger: Broken pipe 
  25. D/dalvikvm( 3288): Debugger has detached; object registry had 1 entries 
  26. D/GpsLocationProvider( 174): setMinTime 1 
  27. W/GpsLocationProvider( 174): Duplicate add listener for uid 10071 
  28. D/GpsLocationProvider( 174): startNavigating 
  29. D/libgps ( 174): qct_gps_set_position_mode = 1, fix_frequency = 1 
  30. D/libgps ( 174): qct_gps_start 
  31. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  32. V/libgps ( 174): DeferredActionThread calling send_get_position 
  33. D/AndroidRuntime( 3288): Shutting down VM 
  34. W/dalvikvm( 3288): threadid=1: thread exiting with uncaught exception (group=0x4001d7e8) 
  35. V/libgps ( 174): PD command:  
  36. V/libgps ( 174): RPC_PDSM_PD_CMD_GET_POS 
  37. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  38. V/libgps ( 174): PD event:  
  39. V/libgps ( 174): PDSM_PD_EVENT_BEGIN  
  40. D/libgps ( 174): report status : 1 
  41. D/GpsLocationProvider( 174): Acquiring wakelock 
  42. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  43. V/libgps ( 174): PD event:  
  44. V/libgps ( 174): PDSM_PD_EVENT_GPS_BEGIN 
  45. D/libgps ( 174): report status : 3 
  46. D/NetworkLocationProvider( 174): onDataConnectionStateChanged 3 
  47. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  48. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  49. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  50. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  51. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  52. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  53. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  54. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  55. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  56. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  57. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  58. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  59. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  60. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  61. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  62. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  63. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  64. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  65. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  66. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  67. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  68. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  69. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  70. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  71. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  72. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  73. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  74. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  75. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  76. I/Process ( 3288): Sending signal. PID: 3288 SIG: 9 
  77. W/GpsLocationProvider( 174): Unneeded remove listener for uid 1000 
  78. D/GpsLocationProvider( 174): stopNavigating 
  79. D/libgps ( 174): qct_gps_stop 
  80. D/libgps ( 174): report status : 2 
  81. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  82. V/libgps ( 174): DeferredActionThread calling send_end_session 
  83. V/libgps ( 174): PD command:  
  84. V/libgps ( 174): RPC_PDSM_PD_CMD_END_SESSION 
  85. V/libgps ( 174): PD event:  
  86. V/libgps ( 174): PDSM_PD_EVENT_END  
  87. V/libgps ( 174): PD event:  
  88. V/libgps ( 174): PDSM_PD_EVENT_DONE  
  89. I/GPSButton( 174): Update State 
  90. D/dalvikvm( 174): GC_EXTERNAL_ALLOC freed 9130 objects / 438696 bytes in 75ms 
  91. W/Process ( 174): Unable to open /proc/1324/status 
  92. W/Process ( 174): Unable to open /proc/1445/status 
  93. D/alogcat ( 3249): stopping ... 
  94. D/alogcat ( 3249): resumed 
  95. D/alogcat ( 3249): canceling periodic saves 
  96. D/dalvikvm( 3249): GC_FOR_MALLOC freed 8810 objects / 616608 bytes in 40ms 
  97. D/dalvikvm( 3249): GC_FOR_MALLOC freed 7342 objects / 529752 bytes in 32ms 
  98. D/dalvikvm( 3249): GC_FOR_MALLOC freed 7396 objects / 495888 bytes in 34ms 
  99. I/ActivityManager( 174): Displayed activity org.jtb.alogcat/.LogActivity: 670 ms (total 6921 ms) 
  100. V/libgps ( 174): DeferredActionThread pthread_cond_wait returned 
  101. V/libgps ( 174): PD event:  
  102. V/libgps ( 174): PDSM_PD_EVENT_GPS_DONE 
  103. D/libgps ( 174): report status : 4 
  104. D/GpsLocationProvider( 174): Releasing wakelock 
  105. I/dalvikvm( 3249): Jit: resizing JitTable from 4096 to 8192 
qubit
Freshman
Freshman
 
Posts: 3
Joined: Thu Feb 11, 2010 1:00 pm

Top

Re: App start when GPS is enabled crashes

Postby Vulinux » Wed Nov 17, 2010 2:47 pm

You should check for null on
Code: Select all
mostRecentLocation = locationManager.getLastKnownLocation(provider);

If there hasn't been any last known Location, it returns null, which hasn't any long and lat ;)
Vulinux
Freshman
Freshman
 
Posts: 9
Joined: Thu Nov 04, 2010 3:46 pm
Location: Germany

Re: App start when GPS is enabled crashes

Postby qubit » Wed Nov 17, 2010 2:51 pm

Vulinux wrote:You should check for null on
Code: Select all
mostRecentLocation = locationManager.getLastKnownLocation(provider);

If there hasn't been any last known Location, it returns null, which hasn't any long and lat ;)


Thank you. I'll look into it and post back how I'm going.
qubit
Freshman
Freshman
 
Posts: 3
Joined: Thu Feb 11, 2010 1:00 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 2 guests