Created
November 16, 2014 03:11
-
-
Save kazuooooo/1706e120c7dc3e2d3a69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.AlertDialog; | |
import android.app.Dialog; | |
import android.app.DialogFragment; | |
import android.content.DialogInterface; | |
import android.os.Bundle; | |
import android.view.WindowManager; | |
/** | |
* Created by matsumotokazuya on 2014/11/16. | |
*/ | |
public class AlertDemo extends DialogFragment { | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState){ | |
// ダイアログが表示されたらが鳴ったらスクリーンをオンにして、ロックを外す | |
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); | |
// アラートDialogBuilderを作成 | |
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | |
// アラートダイアログにタイトルをセット | |
builder.setTitle("Alarm"); | |
// アラートダイアログの中身をセット | |
builder.setMessage("An Alarm by AlarmManager"); | |
// イベントリスナーにOKボタンを定義 | |
builder.setPositiveButton("OK",new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
// OKがクリックされたらアプリケーションを終了 | |
getActivity().finish(); | |
} | |
}); | |
//Creating the Alert Dialog Window | |
return builder.create(); | |
} | |
//もしユーザーがアプリを終了せずにBackボタンを押しても強制的にアプリを終了する | |
@Override | |
public void onDestroy(){ | |
super.onDestroy(); | |
getActivity().finish(): | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment