I have a Service which is executed once in every 5 minute.It shows an AlertDialog when executed.I want to start a Fragment on AlertDialog button click.I tried to start the Fragment like 
android.app.FragmentManager fm = ((Activity) getApplicationContext()).getFragmentManager();
but gives exception java.lang.ClassCastException: android.app.Application cannot be cast to android.app.Activity.
This is my code for AlertDialog:
Handler mHandler = new Handler(getMainLooper());
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                final AlertDialog alertDialog = new AlertDialog.Builder(getApplicationContext(),R.style.Theme_AppCompat_Light_Dialog_Alert)
                                .create();
                             // Setting Dialog Title
                                alertDialog.setTitle(eventNameEnglish);
                                // Setting Dialog Message
                                alertDialog.setMessage(eventAddressEnglish+"\n"+duration);
                        // Setting  View Details Button
                        alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,"View Details", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                android.app.FragmentManager fm = ((Activity) getApplicationContext()).getFragmentManager();
                                dialog_fragment = new DetailFragment("Events",
                                        eventNameEnglish, eventAddressEnglish,
                                        eventContactNumberEnglish, eventEmailEnglish, eventFaxEnglish,
                                        duration,eventOrganizerNameEnglish,
                                        eventDescriptionEnglish,eventFullDescriptionEnglish,
                                        eventLocationEnglish,eventImageEnglish,
                                        eventWebsiteEnglish
                                        );
                                dialog_fragment.show(fm, "detailScreen");
                            }
                        });
                        // Setting Cancel Button
                                alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE,"Cancel", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        alertDialog.dismiss();
                                    }
                                });
                        // Showing Alert Message
                        alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                        alertDialog.show();
                            }
                        });
How to do this?Please help.
 
     
     
    