Merge "Bluetooth : fix for crashing alertDialogbox"

This commit is contained in:
Jake Hamby
2011-07-25 17:21:58 -07:00
committed by Android (Google) Code Review
2 changed files with 11 additions and 1 deletions

View File

@@ -79,6 +79,10 @@ public final class LocalBluetoothManager {
return mContext;
}
public Context getForegroundActivity() {
return mForegroundActivity;
}
boolean isForegroundActivity() {
return mForegroundActivity != null;
}

8
src/com/android/settings/bluetooth/Utils.java Normal file → Executable file
View File

@@ -89,11 +89,17 @@ final class Utils {
static void showError(Context context, String name, int messageResId) {
String message = context.getString(messageResId, name);
new AlertDialog.Builder(context)
LocalBluetoothManager manager = LocalBluetoothManager.getInstance(context);
Context activity = manager.getForegroundActivity();
if(manager.isForegroundActivity()) {
new AlertDialog.Builder(activity)
.setIcon(android.R.drawable.ic_dialog_alert)
.setTitle(R.string.bluetooth_error_title)
.setMessage(message)
.setPositiveButton(android.R.string.ok, null)
.show();
} else {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
}
}