anongit / mytracks

Automatically exported from code.google.com/p/mytracks
0 stars 0 forks source link

Can't create handler inside thread that has not called Looper.prepare() #197

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Start MyTracks and start recording a track
2. Hit Home button
3. Kill the tracking service using (Settings/manage apps).
4. Start a new track

What is the expected output? What do you see instead?

D/MyTracks( 1427): MyTracks.onResume
D/MyTracks( 1427): MyTracks: Trying to bind to track recording service...
D/MyTracks( 1427): MyTracks: ...bind finished!
D/MyTracks( 1427): MyTracksMap.onRestart
D/MyTracks( 1427): MyTracksMap.onStart
D/MyTracks( 1427): MyTracksMap.onResume
D/MyTracks( 1427): MyTracksMap: ContentObserver.onChange
D/MyTracks( 1427): MyTracksMap: ContentObserver.onChange waypoints
D/MyTracks( 1427): MyTracksMap: Using location provider gps
D/MyTracks( 1427): MyTracksMap: Now registering sensor listeners.
D/MyTracks( 1427): MyTracksMap: Network location update received.
D/MyTracks( 1794): TrackRecordingService.startNewTrack
D/MyTracks( 1794): Preparing to register location listener w/ 
TrackRecordingService...
E/MyTracks( 1794): Could not register location listener: Can't create handler 
inside thread that has not called Looper.prepare()
E/MyTracks( 1794): java.lang.RuntimeException: Can't create handler inside 
thread that has not called Looper.prepare()
E/MyTracks( 1794):  at android.os.Handler.<init>(Handler.java:121)
E/MyTracks( 1794):  at 
android.location.LocationManager$ListenerTransport$1.<init>(LocationManager.java
:173)
E/MyTracks( 1794):  at 
android.location.LocationManager$ListenerTransport.<init>(LocationManager.java:1
73)
E/MyTracks( 1794):  at 
android.location.LocationManager._requestLocationUpdates(LocationManager.java:57
9)
E/MyTracks( 1794):  at 
android.location.LocationManager.requestLocationUpdates(LocationManager.java:446
)
E/MyTracks( 1794):  at 
com.google.android.apps.mytracks.services.TrackRecordingService.registerLocation
Listener(TrackRecordingService.java:358)
E/MyTracks( 1794):  at 
com.google.android.apps.mytracks.services.TrackRecordingService.startNewTrack(Tr
ackRecordingService.java:973)
E/MyTracks( 1794):  at 
com.google.android.apps.mytracks.services.TrackRecordingService$2.startNewTrack(
TrackRecordingService.java:881)
E/MyTracks( 1794):  at 
com.google.android.apps.mytracks.services.ITrackRecordingService$Stub.onTransact
(ITrackRecordingService.java:52)
E/MyTracks( 1794):  at android.os.Binder.execTransact(Binder.java:320)
E/MyTracks( 1794):  at dalvik.system.NativeStart.run(Native Method)
D/MyTracks( 1794): SplitManager: Distance splits disabled.
D/MyTracks( 1794): Updating auto-resume retry attempts to: 0
D/MyTracks( 1794): TrackRecordingService.sharedPreferenceChanged: selectedTrack
D/MyTracks( 1794): TrackRecordingService.onSharedPreferenceChanged
D/MyTracks( 1794): Preparing to register location listener w/ 
TrackRecordingService...
E/MyTracks( 1794): Could not register location listener: Can't create handler 
inside thread that has not called Looper.prepare()
E/MyTracks( 1794): java.lang.RuntimeException: Can't create handler inside 
thread that has not called Looper.prepare()

Original issue reported on code.google.com by ba...@google.com on 23 Oct 2010 at 5:36

GoogleCodeExporter commented 9 years ago
Ah, I've realized that there is already a hacky way to handle this case (see 
showDialogSafely).  Unfortunately, this is wrong (and is not used in a few 
important cases).  The reason it's wrong, because it just fixes a side effect 
of bad coding.

According to the docs, we have two ways to fix the original issue:

1) If the confirmation dialog is part of the same activity that started a long 
running action, it should be tied to the activity and should be properly 
terminated on the activity destuction, e.g. if MyTracks activity starts a track 
export, it should cancel it in its onDestroy
2) If the action is to be run regardless whether its creator is destroyed or 
not, we should use the global context of the application (which is not tied to 
any particular activity).

In both cases, the right fix is to remove showDialogSafely and fix 
showMessageDialog and double check all Runnables if they are properly accessing 
activities.

Original comment by ba...@google.com on 8 Nov 2010 at 4:13

GoogleCodeExporter commented 9 years ago
There is another instance of this bug:

D/MyTracks( 7296): TrackRecordingService.shutdownAnnouncer: null
E/JavaBinder( 7296): *** Uncaught remote exception!  (Exceptions are not yet 
supported across processes.)
E/JavaBinder( 7296): java.lang.RuntimeException: Can't create handler inside 
thread that has not called Looper.prepare()
E/JavaBinder( 7296):    at android.os.Handler.<init>(Handler.java:121)
E/JavaBinder( 7296):    at 
android.telephony.PhoneStateListener$2.<init>(PhoneStateListener.java:299)
E/JavaBinder( 7296):    at 
android.telephony.PhoneStateListener.<init>(PhoneStateListener.java:299)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.StatusAnnouncerTask$1.<init>(StatusAnn
ouncerTask.java:76)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.StatusAnnouncerTask.<init>(StatusAnnou
ncerTask.java:76)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.StatusAnnouncerTask.<init>(StatusAnnou
ncerTask.java:89)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.StatusAnnouncerFactory.create(StatusAn
nouncerFactory.java:44)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.TrackRecordingService.setUpAnnouncer(T
rackRecordingService.java:688)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.TrackRecordingService.setAnnouncementF
requency(TrackRecordingService.java:1062)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.PreferenceManager.onSharedPreferenceCh
anged(PreferenceManager.java:134)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.TrackRecordingService.onSharedPreferen
ceChanged(TrackRecordingService.java:623)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.TrackRecordingService$2.sharedPreferen
ceChanged(TrackRecordingService.java:993)
E/JavaBinder( 7296):    at 
com.google.android.apps.mytracks.services.ITrackRecordingService$Stub.onTransact
(ITrackRecordingService.java:144)
E/JavaBinder( 7296):    at android.os.Binder.execTransact(Binder.java:320)
E/JavaBinder( 7296):    at dalvik.system.NativeStart.run(Native Method)
D/MyTracks( 7286): MyTracksMap.onSharedPreferenceChanged: announcementFrequency

Original comment by ba...@google.com on 16 Nov 2010 at 3:47

GoogleCodeExporter commented 9 years ago
This is one of the bugs I fixed in my change:
http://code.google.com/r/sandordornbush-bugfix-mac/source/detail?r=fd0e3ae70cd54
8183206da8d9ceb45d6a952ef9d

Original comment by sandordo...@google.com on 16 Nov 2010 at 4:19

GoogleCodeExporter commented 9 years ago
I've fixed both cases, http://code.google.com/r/bartn-mytracks/source/list.

Original comment by ba...@google.com on 18 Nov 2010 at 7:13