【问题标题】:android weird onCreate / onDestroy balanceandroid 奇怪的 onCreate / onDestroy 平衡
【发布时间】:2010-09-25 01:37:18
【问题描述】:

有没有办法告诉 Android 我希望后续对 startActivity() 的调用都恢复目标活动,而不是一遍又一遍地创建它?有什么解决方法吗?

谢谢

【问题讨论】:

    标签: android singleton android-activity oncreate android-lifecycle


    【解决方案1】:

    根据您的需要,在创建意图时尝试使用FLAG_ACTIVITY_CLEAR_TOPFLAG_ACTIVITY_REORDER_TO_FRONT

    Intent intent = new Intent(this, NameOfActivityClass.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    

    【讨论】:

    • 这些标志似乎是我所追求的,但它们都不起作用。有什么特别需要进入清单文件的吗?
    • 标记为答案。我没有重写 onDestroy 方法,而是 onStop,这就是我感到困惑的原因。但是,Android 决定在系统负载几乎为 0 时销毁该活动(当前正在运行的任务的一部分)仍然很奇怪。
    猜你喜欢
    • 2016-08-09
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多