Android service里面啟動activity和alertdialog .


啟動activity源碼:(記得要加上Intent.FLAG_ACTIVITY_NEW_TASK)

  1. Intent intent = new Intent();
  2. intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  3. intent.setClass(getApplicationContext(),FileBrowserActivity.class);
  4. startActivity(intent);

啟動alertDialog源碼:

  1. AlertDialog.Builder builder = new AlertDialog.Builder(this);
  2. builder.setMessage("是否接受文件?")
  3. .setPositiveButton("是", new DialogInterface.OnClickListener() {
  4. @Override
  5. publicvoid onClick(DialogInterface dialog, int which) {
  6. }
  7. }).setNegativeButton("否", new OnClickListener() {
  8. @Override
  9. publicvoid onClick(DialogInterface dialog, int which) {
  10. }
  11. });
  12. AlertDialog ad = builder.create();
  13. // ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG); //系統中關機對話框就是這個屬性
  14. ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
  15. ad.setCanceledOnTouchOutside(false); //點擊外面區域不會讓dialog消失
  16. ad.show();
還要加上權限 
  1. <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM