Android Open Source - Pairs Alarm Activity






From Project

Back to project page Pairs.

License

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.

Java Source Code

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();
  }
}




Java Source Code List

com.example.pairs.AlarmActivity.java
com.example.pairs.ChooseContactActivity.java
com.example.pairs.Function.java
com.example.pairs.HelpActivity.java
com.example.pairs.Help.java
com.example.pairs.MainActivity.java
com.example.pairs.OurPage.java
com.example.pairs.Ours.java
com.example.pairs.PhotoActivity.java
com.example.pairs.SMSReceiver.java
com.example.pairs.SetContactActivity.java