Tuesday, August 19, 2014

How to Display an Alert Dialog in a Fragment

 Display an Alert Dialog in a Fragment

//SplashScreenActivity.class is your Launcher Activity
 // In Case of Activity instead of fragment Replace getActivity() with getApplicationContext()

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setCancelable(false);
            builder.setTitle(Html.fromHtml("<font color='#7F02AE'><b>Star Cineplex</b></font>"));
            builder.setMessage(Html.fromHtml("<font color='#120049'>Your data services are not working.Please check your data services.</font>"));
            builder.setPositiveButton(Html.fromHtml("<font color='#7F02AE'><b>OK</b></font>"), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                                         
  Intent intent = new Intent(getActivity(), SplashScreenActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        intent.putExtra("EXIT", true);
                        startActivity(intent);
            
                                  
                   
                }
            });
                   AlertDialog alert=builder.create();
            alert.show();

Now at OnCreate of the Launcher Activity(eg. SplashScreenActivity.class)

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.loading_image_mn);
        //To exit
        if (getIntent().getBooleanExtra("EXIT", false)) {
            SplashScreenActivity.this.finish();
            System.exit(0);
        }
Like the following:
                     
            

1 comment:

  1. Gambling & Casinos - MapyRO
    Find the best and 영천 출장샵 newest casinos in 의정부 출장마사지 Las Vegas, NV with Mapyro. We compare the 부산광역 출장안마 most popular 김제 출장안마 casinos and casinos with the best slots games in our collection. 강원도 출장마사지

    ReplyDelete