本文整理匯總了Java中android.app.Activity.isDestroyed方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.isDestroyed方法的具體用法?Java Activity.isDestroyed怎麽用?Java Activity.isDestroyed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Activity
的用法示例。
在下文中一共展示了Activity.isDestroyed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getContext
import android.app.Activity; //導入方法依賴的package包/類
/**
* get the activity which is owned. if the activity is finish or destroyed or recycled. it return null.
* @return the activity, may be null.
*/
public Context getContext(){
final Context t = mWeakActivity.get();
if(t != null && t instanceof Activity) {
final Activity ac = (Activity) t;
if (ac.isFinishing()) {
return null;
}
if (Build.VERSION.SDK_INT >= 17 && ac.isDestroyed()) {
Log.w("WeakActivityOwner","getActivity(): memory leaked ? t = "
+ t.getClass().getName());
return null;
}
return t;
}
return null;
}
示例2: buildDialog
import android.app.Activity; //導入方法依賴的package包/類
public static Dialog buildDialog(Context context, boolean cancleable, boolean outsideTouchable) {
if (context instanceof Activity){//todo keycode
Activity activity = (Activity) context;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (activity.isDestroyed()){
context = StyledDialog.context;
}
}
}
Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(cancleable);
dialog.setCanceledOnTouchOutside(outsideTouchable);
return dialog;
}
示例3: secureSettings
import android.app.Activity; //導入方法依賴的package包/類
public void secureSettings(Activity activity, final Context appContext, Exception e, String page) { //exception function for a Secure Settings problem
Log.e(page, e.getMessage()); //log the error
e.printStackTrace();
if (!activity.isDestroyed()) {
new AlertDialog.Builder(activity) //show a dialog with the error and prompt user to set up permissions again
.setIcon(alertRed)
.setTitle(Html.fromHtml("<font color='#ff0000'>" + activity.getResources().getText(R.string.error) + "</font>"))
.setMessage(activity.getResources().getText(R.string.perms_not_set) + "\n\n\"" + e.getMessage() + "\"\n\n" + activity.getResources().getText(R.string.prompt_setup))
.setPositiveButton(activity.getResources().getText(R.string.yes), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(appContext, SetupActivity.class);
intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK);
appContext.startActivity(intent);
}
})
.setNegativeButton(activity.getResources().getText(R.string.no), null)
.show();
}
}
示例4: finishActivitySync
import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
static public void finishActivitySync(Activity activity, Instrumentation instrumentation, boolean doFinish)
{
if (doFinish)
activity.finish();
//give activity one minute to finish
long currentTime = System.currentTimeMillis();
boolean finishTimeout = false;
int activityHash = activity.hashCode();
boolean isDestroyed = false;
while (!isDestroyed && !finishTimeout) {
instrumentation.waitForIdleSync();
finishTimeout = (System.currentTimeMillis() - currentTime) > 140000;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
isDestroyed = activity.isDestroyed();
}else {
isDestroyed = (Boolean)callMethod(null, activity.getWindow(), "isDestroyed", null);
}
}
if (finishTimeout) {
WebtrekkLogging.log("finishActivitySync: finished by timeout. Hash:" + activityHash);
}
}
示例5: isActivityDestoryed
import android.app.Activity; //導入方法依賴的package包/類
public static boolean isActivityDestoryed(Activity activity) {
if (activity == null) {
return true;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return activity.isDestroyed();
} else {
return activity.isFinishing();
}
}
示例6: isActivityFinish
import android.app.Activity; //導入方法依賴的package包/類
public boolean isActivityFinish(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return activity.isDestroyed() || activity.isFinishing();
} else {
return activity.isFinishing();
}
}
示例7: getCurrentActivity
import android.app.Activity; //導入方法依賴的package包/類
public Activity getCurrentActivity() {
Activity currentActivity = null;
if (sCurrentActivityWeakRef != null) {
currentActivity = sCurrentActivityWeakRef.get();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if(currentActivity ==null || currentActivity.isDestroyed()){
currentActivity = null;
}
}
}
return currentActivity;
}
示例8: fixContext
import android.app.Activity; //導入方法依賴的package包/類
/**
* 混合上下文
*/
public static BuildBean fixContext(BuildBean bean) {
if (bean.mContext == null) {
bean.mContext = DialogUIUtils.appContext;
} else if (bean.mContext instanceof Activity) {
Activity activity = (Activity) bean.mContext;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (activity.isDestroyed()) {
bean.mContext = DialogUIUtils.appContext;
}
}
}
return bean;
}
示例9: setDialogStyle
import android.app.Activity; //導入方法依賴的package包/類
public static void setDialogStyle(Context context, Dialog dialog, int measuredHeight, BuildBean bean) {
if (dialog == null) {
return;
}
Window window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setGravity(bean.gravity);
WindowManager.LayoutParams wl = window.getAttributes();
// 以下這兩句是為了保證按鈕可以水平滿屏
int width = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
int height = (int) (((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight() * 0.9);
if (bean.type != DialogConfig.TYPE_MD_LOADING) {
wl.width = (int) (width * 0.94); // todo keycode to keep gap
} else {
wl.width = ViewGroup.LayoutParams.WRAP_CONTENT;
}
wl.height = ViewGroup.LayoutParams.WRAP_CONTENT; //TODO 一般情況下為wrapcontent,最大值為height*0.9
if (measuredHeight > height) {
wl.height = height;
}
if (context instanceof Activity) {
Activity activity1 = (Activity) context;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (activity1.isDestroyed()) {
context = DialogUIUtils.appContext;
}
}
} else {
wl.type = WindowManager.LayoutParams.TYPE_TOAST;
//todo keycode to improve window level,同時要讓它的後麵半透明背景也攔截事件,不要傳遞到下麵去
//todo 單例化,不然連續彈出兩次,隻能關掉第二次的
}
dialog.onWindowAttributesChanged(wl);
}
示例10: cancelDialog
import android.app.Activity; //導入方法依賴的package包/類
/**
* 退出加載提示
*/
private void cancelDialog() {
if (dialog != null && dialog.isShowing()) {
Activity activity = dialog.getOwnerActivity();
if (activity==null||activity.isDestroyed()||activity.isFinishing()){
return;
}
dialog.dismiss();
}
}
示例11: setDialogStyle
import android.app.Activity; //導入方法依賴的package包/類
public static void setDialogStyle(Context context, Dialog dialog, int measuredHeight, BuildBean bean) {
if (dialog == null) {
return;
}
Window window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setGravity(bean.gravity);
WindowManager.LayoutParams wl = window.getAttributes();
// 以下這兩句是為了保證按鈕可以水平滿屏
int width = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
int height = (int) (((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight() * 0.9);
if (bean.type != CommonConfig.TYPE_MD_LOADING_VERTICAL) {
wl.width = (int) (width * 0.94); // todo keycode to keep gap
} else {
wl.width = ViewGroup.LayoutParams.WRAP_CONTENT;
}
wl.height = ViewGroup.LayoutParams.WRAP_CONTENT; //TODO 一般情況下為wrapcontent,最大值為height*0.9
if (measuredHeight > height) {
wl.height = height;
}
if (context instanceof Activity) {
Activity activity1 = (Activity) context;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (activity1.isDestroyed()) {
context = DialogUIUtils.appContext;
}
}
} else {
wl.type = WindowManager.LayoutParams.TYPE_TOAST;
//todo keycode to improve window level,同時要讓它的後麵半透明背景也攔截事件,不要傳遞到下麵去
//todo 單例化,不然連續彈出兩次,隻能關掉第二次的
}
dialog.onWindowAttributesChanged(wl);
}
示例12: showImpl
import android.app.Activity; //導入方法依賴的package包/類
@UiThread
private void showImpl(Params params) {
if (mContext instanceof Activity) {
Activity ac = ((Activity) mContext);
if (ac.isFinishing()) {
//ignore
return;
}
if (Build.VERSION.SDK_INT >= 17 && ac.isDestroyed()) {
//ignore
return;
}
}
if (params.start != null) {
params.start.run();
}
if (mWindowView.getParent() != null) {
mWM.removeView(mWindowView);
}
mShowing = true;
//mWindowView.setY(-mWindowView.getMeasuredHeight());
mWM.addView(mWindowView, mUsingConfig.wlp);
//duration < 0, means until cancel.
if (mUsingConfig.duration > 0) {
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_CANCEL, params),
mUsingConfig.duration);
}
}
示例13: canLoadImage
import android.app.Activity; //導入方法依賴的package包/類
public static boolean canLoadImage(Activity activity) {
if (activity == null) {
return true;
}
boolean destroyed = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 &&
activity.isDestroyed();
if (destroyed || activity.isFinishing()) {
return false;
}
return true;
}
示例14: assertNotDestroyed
import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static void assertNotDestroyed(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed()) {
throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
}
}
示例15: assertNotDestroyed
import android.app.Activity; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static void assertNotDestroyed(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed()) {
throw new IllegalArgumentException("You cannot start a load for a destroyed activity");
}
}