forked from upstream-mirrors/OpenTracks
"I see dead threads".
Removing handler threads which were left to die, forever alone with nothing to execute.
This commit is contained in:
@@ -29,8 +29,6 @@ import android.app.ProgressDialog;
|
|||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -91,12 +89,7 @@ public class ExportAllTracks {
|
|||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
HandlerThread handlerThread;
|
new Thread(runner, "SendToMyMaps").start();
|
||||||
Handler handler;
|
|
||||||
handlerThread = new HandlerThread("SendToMyMaps");
|
|
||||||
handlerThread.start();
|
|
||||||
handler = new Handler(handlerThread.getLooper());
|
|
||||||
handler.post(runner);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,7 +110,7 @@ public class ExportAllTracks {
|
|||||||
long recordingTrackId = -1;
|
long recordingTrackId = -1;
|
||||||
if (prefs != null) {
|
if (prefs != null) {
|
||||||
recordingTrackId =
|
recordingTrackId =
|
||||||
prefs.getLong(activity.getString(R.string.recording_track_key), -1);
|
prefs.getLong(activity.getString(R.string.recording_track_key), -1);
|
||||||
}
|
}
|
||||||
if (recordingTrackId != -1) {
|
if (recordingTrackId != -1) {
|
||||||
wakeLock = SystemUtils.acquireWakeLock(activity, wakeLock);
|
wakeLock = SystemUtils.acquireWakeLock(activity, wakeLock);
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2011 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
* the License at
|
* the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
@@ -25,8 +25,6 @@ import android.app.Activity;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.os.PowerManager.WakeLock;
|
import android.os.PowerManager.WakeLock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -45,7 +43,7 @@ import org.xml.sax.SAXException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that will import all GPX tracks in /sdcard/MyTracks/gpx/
|
* A class that will import all GPX tracks in /sdcard/MyTracks/gpx/
|
||||||
*
|
*
|
||||||
* @author David Piggott
|
* @author David Piggott
|
||||||
*/
|
*/
|
||||||
public class ImportAllTracks {
|
public class ImportAllTracks {
|
||||||
@@ -63,12 +61,8 @@ public class ImportAllTracks {
|
|||||||
Log.i(Constants.TAG, "ImportAllTracks: Starting");
|
Log.i(Constants.TAG, "ImportAllTracks: Starting");
|
||||||
fileUtils = new FileUtils();
|
fileUtils = new FileUtils();
|
||||||
gpxPath = fileUtils.buildExternalDirectoryPath("gpx");
|
gpxPath = fileUtils.buildExternalDirectoryPath("gpx");
|
||||||
HandlerThread handlerThread;
|
|
||||||
Handler handler;
|
new Thread(runner).start();
|
||||||
handlerThread = new HandlerThread("ImportAllTracks");
|
|
||||||
handlerThread.start();
|
|
||||||
handler = new Handler(handlerThread.getLooper());
|
|
||||||
handler.post(runner);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Runnable runner = new Runnable() {
|
private final Runnable runner = new Runnable() {
|
||||||
|
|||||||
@@ -32,8 +32,6 @@ import com.google.wireless.gdata.docs.XmlDocsGDataParserFactory;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -46,7 +44,7 @@ import java.io.IOException;
|
|||||||
public class SendToDocs {
|
public class SendToDocs {
|
||||||
/** The GData service name for Google Spreadsheets (aka Trix) */
|
/** The GData service name for Google Spreadsheets (aka Trix) */
|
||||||
public static final String GDATA_SERVICE_NAME_TRIX = "wise";
|
public static final String GDATA_SERVICE_NAME_TRIX = "wise";
|
||||||
|
|
||||||
/** The GData service name for the Google Docs Document List */
|
/** The GData service name for the Google Docs Document List */
|
||||||
public static final String GDATA_SERVICE_NAME_DOCLIST = "writely";
|
public static final String GDATA_SERVICE_NAME_DOCLIST = "writely";
|
||||||
|
|
||||||
@@ -55,8 +53,6 @@ public class SendToDocs {
|
|||||||
private final AuthManager docListAuth;
|
private final AuthManager docListAuth;
|
||||||
private final ProgressIndicator progressIndicator;
|
private final ProgressIndicator progressIndicator;
|
||||||
private final boolean metricUnits;
|
private final boolean metricUnits;
|
||||||
private final HandlerThread handlerThread;
|
|
||||||
private final Handler handler;
|
|
||||||
|
|
||||||
private boolean createdNewSpreadSheet = false;
|
private boolean createdNewSpreadSheet = false;
|
||||||
|
|
||||||
@@ -81,21 +77,17 @@ public class SendToDocs {
|
|||||||
} else {
|
} else {
|
||||||
metricUnits = true;
|
metricUnits = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
handlerThread = new HandlerThread("SendToGoogleDocs");
|
|
||||||
handlerThread.start();
|
|
||||||
handler = new Handler(handlerThread.getLooper());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendToDocs(final long trackId) {
|
public void sendToDocs(final long trackId) {
|
||||||
Log.d(Constants.TAG,
|
Log.d(Constants.TAG,
|
||||||
"Sending to Google Docs: trackId = " + trackId);
|
"Sending to Google Docs: trackId = " + trackId);
|
||||||
handler.post(new Runnable() {
|
new Thread("SendToGoogleDocs") {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
doUpload(trackId);
|
doUpload(trackId);
|
||||||
}
|
}
|
||||||
});
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doUpload(long trackId) {
|
private void doUpload(long trackId) {
|
||||||
@@ -163,7 +155,7 @@ public class SendToDocs {
|
|||||||
GDataWrapper<GDataServiceClient> docListWrapper = new GDataWrapper<GDataServiceClient>();
|
GDataWrapper<GDataServiceClient> docListWrapper = new GDataWrapper<GDataServiceClient>();
|
||||||
docListWrapper.setAuthManager(docListAuth);
|
docListWrapper.setAuthManager(docListAuth);
|
||||||
docListWrapper.setRetryOnAuthFailure(true);
|
docListWrapper.setRetryOnAuthFailure(true);
|
||||||
|
|
||||||
GDataWrapper<GDataServiceClient> trixWrapper = new GDataWrapper<GDataServiceClient>();
|
GDataWrapper<GDataServiceClient> trixWrapper = new GDataWrapper<GDataServiceClient>();
|
||||||
trixWrapper.setAuthManager(trixAuth);
|
trixWrapper.setAuthManager(trixAuth);
|
||||||
trixWrapper.setRetryOnAuthFailure(true);
|
trixWrapper.setRetryOnAuthFailure(true);
|
||||||
@@ -191,7 +183,7 @@ public class SendToDocs {
|
|||||||
// First try to find the spreadsheet:
|
// First try to find the spreadsheet:
|
||||||
String spreadsheetId = null;
|
String spreadsheetId = null;
|
||||||
try {
|
try {
|
||||||
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
||||||
sheetTitle);
|
sheetTitle);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.i(Constants.TAG, "Spreadsheet lookup failed.", e);
|
Log.i(Constants.TAG, "Spreadsheet lookup failed.", e);
|
||||||
@@ -207,16 +199,16 @@ public class SendToDocs {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.e(Constants.TAG, "Sleep interrupted", e);
|
Log.e(Constants.TAG, "Sleep interrupted", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
||||||
sheetTitle);
|
sheetTitle);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.i(Constants.TAG, "2nd spreadsheet lookup failed.", e);
|
Log.i(Constants.TAG, "2nd spreadsheet lookup failed.", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We were unable to find an existing spreadsheet, so create a new one.
|
// We were unable to find an existing spreadsheet, so create a new one.
|
||||||
progressIndicator.setProgressValue(70);
|
progressIndicator.setProgressValue(70);
|
||||||
if (spreadsheetId == null) {
|
if (spreadsheetId == null) {
|
||||||
@@ -248,7 +240,7 @@ public class SendToDocs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
||||||
sheetTitle);
|
sheetTitle);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.i(Constants.TAG, "Failed create-failed lookup", e);
|
Log.i(Constants.TAG, "Failed create-failed lookup", e);
|
||||||
@@ -263,9 +255,9 @@ public class SendToDocs {
|
|||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Log.e(Constants.TAG, "Sleep interrupted", e);
|
Log.e(Constants.TAG, "Sleep interrupted", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
spreadsheetId = docsHelper.requestSpreadsheetId(docListWrapper,
|
||||||
sheetTitle);
|
sheetTitle);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.i(Constants.TAG, "Failed create-failed relookup", e);
|
Log.i(Constants.TAG, "Failed create-failed relookup", e);
|
||||||
@@ -293,7 +285,7 @@ public class SendToDocs {
|
|||||||
|
|
||||||
progressIndicator.setProgressValue(90);
|
progressIndicator.setProgressValue(90);
|
||||||
|
|
||||||
docsHelper.addTrackRow(activity, trixAuth, spreadsheetId, worksheetId,
|
docsHelper.addTrackRow(activity, trixAuth, spreadsheetId, worksheetId,
|
||||||
track, metricUnits);
|
track, metricUnits);
|
||||||
Log.i(Constants.TAG, "Done uploading to docs.");
|
Log.i(Constants.TAG, "Done uploading to docs.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.HandlerThread;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -426,11 +424,7 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
|||||||
final SendToMyMaps sender = new SendToMyMaps(this, sendToMyMapsMapId, lastAuth,
|
final SendToMyMaps sender = new SendToMyMaps(this, sendToMyMapsMapId, lastAuth,
|
||||||
sendTrackId, this /*progressIndicator*/, onCompletion);
|
sendTrackId, this /*progressIndicator*/, onCompletion);
|
||||||
|
|
||||||
// TODO: We're leaking this thread!
|
new Thread(sender, "SendToMyMaps").start();
|
||||||
HandlerThread handlerThread = new HandlerThread("SendToMyMaps");
|
|
||||||
handlerThread.start();
|
|
||||||
Handler handler = new Handler(handlerThread.getLooper());
|
|
||||||
handler.post(sender);
|
|
||||||
|
|
||||||
return SendState.NOT_READY;
|
return SendState.NOT_READY;
|
||||||
}
|
}
|
||||||
@@ -485,14 +479,11 @@ public class SendActivity extends Activity implements ProgressIndicator {
|
|||||||
executeStateMachine(SendState.SEND_TO_FUSION_TABLES_DONE);
|
executeStateMachine(SendState.SEND_TO_FUSION_TABLES_DONE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
final SendToFusionTables sender = new SendToFusionTables(this, lastAuth,
|
final SendToFusionTables sender = new SendToFusionTables(this, lastAuth,
|
||||||
sendTrackId, this /*progressIndicator*/, onCompletion);
|
sendTrackId, this /*progressIndicator*/, onCompletion);
|
||||||
|
|
||||||
// TODO: We're leaking this thread!
|
new Thread(sender, "SendToFusionTables").start();
|
||||||
HandlerThread handlerThread = new HandlerThread("SendToFusionTables");
|
|
||||||
handlerThread.start();
|
|
||||||
Handler handler = new Handler(handlerThread.getLooper());
|
|
||||||
handler.post(sender);
|
|
||||||
|
|
||||||
return SendState.NOT_READY;
|
return SendState.NOT_READY;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user