毕业设计做的是基于安卓平台的备忘录闹钟,整个程序可以运行,但是闹钟可以新建多个,只有第一个设置的闹钟可以
正确进行提醒,后面的闹钟事件一到时间整个程序就会出错,求大神帮忙,本来对安卓知识就知道甚少,也不会进行错误调试,希望能有大神来帮我看一下,谢谢了。
这是闹钟事件触发时弹出的提醒对话框的java方法:
public class AlertDialogActivity extends Activity implements OnClickListener{
public static AlertDialogActivity context = null;
private MediaPlayer player = new MediaPlayer();
WakeLock mWakelock;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //在锁屏时仍能启动闹钟
context = this;
try{
Uri localUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_ALARM);
if((player != null) && (localUri != null))
{
player.setDataSource(context,localUri);
player.prepare();
player.setLooping(false);
player.start();
}
AlertDialog.Builder localBuilder = new AlertDialog.Builder(context);
localBuilder.setTitle(R.string.alertName);
localBuilder.setMessage("看看该做什么了");
localBuilder.setPositiveButton(R.string.positiveButton,this);
localBuilder.setNegativeButton(R.string.negativeButton,this);
localBuilder.show();
}catch (IllegalArgumentException localIllegalArgumentException)
{
localIllegalArgumentException.printStackTrace();
}
catch (SecurityException localSecurityException)
{
localSecurityException.printStackTrace();
}
catch (IllegalStateException localIllegalStateException)
{
localIllegalStateException.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
switch(which){
case DialogInterface.BUTTON1:
{
Intent intent = new Intent(AlertDialogActivity.this, EditActivity.class);
Bundle b = new Bundle();
b.putString("datetime",getIntent().getStringExtra("datetime"));
b.putString("content", getIntent().getStringExtra("content"));
b.putString("alerttime",getIntent().getStringExtra("alerttime"));
intent.putExtra("android.intent.extra.INTENT", b);
startActivity(intent); //启动转到的Activity
finish();
}
case DialogInterface.BUTTON2:
{
// mWakelock.release();
player.stop();
finish();
}
}
}
}