Back to project page Pairs.
The source code is released under:
MIT License
If you think the Android project Pairs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.pairs; // w w w . j a va 2 s.c om import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.media.MediaPlayer; import android.os.Bundle; import android.view.KeyEvent; public class AlarmActivity extends Activity { String currentfile; MediaPlayer alarmMusic; //?????????????????????????? @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK) { //??????????????????? alarmMusic.stop(); //???????Home?????? Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent); //????Activity finish(); return true; } //?????????????????? else { return super.onKeyDown(keyCode, event); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { //????? ????????MP3??????????????? alarmMusic = MediaPlayer.create(this, R.raw.alarm); //??????? alarmMusic.setLooping(true); //???????? alarmMusic.setVolume(1, 1); //???? alarmMusic.start(); } catch (Exception e) { e.printStackTrace(); } //???????????? new AlertDialog.Builder(AlarmActivity.this).setTitle("???????").setMessage("????????").setPositiveButton("???", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //?????????????????? alarmMusic.stop(); //???????Home?????? Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addCategory(Intent.CATEGORY_HOME); startActivity(intent); //????Activity finish(); } }).show(); } }