Here you can find the source of canShowAlertDialog(Context context)
private static boolean canShowAlertDialog(Context context)
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.app.Activity; import android.content.Context; public class Main { private static boolean canShowAlertDialog(Context context) { // We can only display the alert dialog if mContext is // an Activity context. // FIXME: Should we display dialogs if mContext does // not have the window focus (e.g. if the user is viewing // another Activity when the alert should be displayed) ? // See bug 3166409 return context instanceof Activity; }/* ww w. ja v a 2 s .c o m*/ }