使用以下代码:
private void showDialog(String message) {
try
{
Looper.prepare();
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
UserPrefs.setLogerForException(Log.getStackTraceString(e).toString(),
GlobalContext.Myglobalcontext,ApiConstants.Excption_Log_Message);
}
CustomAlert alertDialog = new CustomAlert();
alertDialog.setTitle(context.getResources().getString(R.string.notification_tite));
alertDialog.setMessage(msg.obj.toString());
alertDialog.setAlertId(Events.MORE_INFO);
alertDialog.setTextGravity(Gravity.LEFT);
ReplicaPrefs.showAlert(alertDialog);
}
};
Message msgObj = handler.obtainMessage();
msgObj.obj = message ;
handler.handleMessage(msgObj);
}
catch(Exception ex)
{
UserPrefs.setLogerForException(Log.getStackTraceString(ex).toString(),
GlobalContext.Myglobalcontext,ApiConstants.Excption_Log_Message);
}
}
一段时间后(不是确切的情况)我有以下错误:
java.lang.RuntimeException:每个线程只能在 android.os.Looper.prepare 创建一个 Looper
有谁知道我哪里出错了?