“强制停止”将 Activity 留在其生命周期的哪个位置?

2024-01-23

假设我的应用程序已启动并正在运行。然后我进入我的设备主屏幕。导航设置>>应用程序>>管理应用程序,选择我的应用程序,然后按Force stop.

Which Activity下次打开应用程序时会调用方法吗?在我因不检查自己而受到攻击之前,我有很多Log我的陈述onCreate, onStart and onResume方法,但实际上没有一个显示在LogCat当应用程序重新打开时。

如果你知道什么状态的答案Force stop将我的申请放入但缺少的Log言论没有任何意义,请分享。我认为除了我缺少的地方之外可能还有其他问题Force stop放置我的程序。

Android Activity LifeCycle: enter image description here

onCreate()

public void onCreate(Bundle savedInstanceState) {
    Log.i( TAG, "Whats going onnnn0" );
    // This calls all inherited methods, as this is a subclass of Activity.
    super.onCreate(savedInstanceState);
    if(D) Log.e(TAG, "+++ ON CREATE +++");
    Log.i( TAG, "Whats going onnnn" );


    // Set the view the main.xml
    setContentView(R.layout.main);
    RelayAPIModel.bluetoothConnected = false;
    // Initialize the connection.
    setupConnection();
    Log.i( TAG, "Whats going onnnn2" );

    // Check how if bluetooth is enabled on this device.
    mService.checkBluetoothState();
    // Initialize stuff from PilotMain() method
    initMain();
    Log.i( TAG, "Whats going onnnn3" );
    // Add listeners to all of the buttons described in main.xml
    buildButtons();
    Log.i( "HERE", "HERE" );
    // If the adapter is null, then Bluetooth is not supported
    if (mService.getAdapter() == null) {
        Toast.makeText(this, R.string.toast_bt_not_avail, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    savedStuff = (SerializableObjects)LocalObjects.readObjectFromFile( getApplicationContext(), "LastDevice.txt" );
    if( savedStuff != null ) {
        hasLastDevice = true;
        Log.i( "HAS", "LAST DEVICE" );
        Log.i( "HAS", savedStuff.getName() );
    } else {
        hasLastDevice = false;
        Log.i( "HAS NO", "LAST DEVICE" );
    }

    pairedDeviceList = new ArrayList<BluetoothDevice>();
    pairedDevices = mService.getAdapter().getBondedDevices();

    for( BluetoothDevice device: pairedDevices ) {
        pairedDeviceList.add( device );
    }
    if( hasLastDevice ) {
        for( int i = 0; i < pairedDeviceList.size(); i++ ) {
            Log.i( "1 HERE HERE", pairedDeviceList.get( i ).getName() );
            Log.i( "1 HEUH?I@JD", savedStuff.getName() );
            if( pairedDeviceList.get( i ).getName().equals( savedStuff.getRealName() ) ) {
                // THIS IS THE DEVICE WE NEED
                previousDevice = pairedDeviceList.get( i );
                i = pairedDeviceList.size();
            }
        }
    }

} 

onStart()

public void onStart() {
    super.onStart();
    if(D) Log.e(TAG, "++ ON START ++");

    savedStuff = (SerializableObjects)LocalObjects.readObjectFromFile( getApplicationContext(), "LastDevice.txt" );
    if( savedStuff != null ) {
        hasLastDevice = true;
        Log.i( "HAS", "LAST DEVICE" );
        Log.i( "HAS", savedStuff.getName() );
    } else {
        hasLastDevice = false;
        Log.i( "HAS NO", "LAST DEVICE" );
    }

    pairedDeviceList = new ArrayList<BluetoothDevice>();
    pairedDevices = mService.getAdapter().getBondedDevices();

    for( BluetoothDevice device: pairedDevices ) {
        pairedDeviceList.add( device );
    }
    if( hasLastDevice ) {
        for( int i = 0; i < pairedDeviceList.size(); i++ ) {
            Log.i( "2 HERE HERE", pairedDeviceList.get( i ).getName() );
            Log.i( "2 HEUH?I@JD", savedStuff.getName() );
            if( pairedDeviceList.get( i ).getName().equals( savedStuff.getRealName() ) ) {
                // THIS IS THE DEVICE WE NEED
                previousDevice = pairedDeviceList.get( i );
                i = pairedDeviceList.size();
            }
        }
    }


    // If BT is not on, request that it be enabled.
    // setupChat() will then be called during onActivityResult
    if (!mService.getAdapter().isEnabled()) {
        Log.i( TAG, "first !isEnabled " );
        Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        Log.i( TAG, "second !isEnabled" );
    // Otherwise, setup the connection
    } else {
        if (mService == null) {
            Log.i( TAG, "setupConnection BEFORE" );
            setupConnection();
            Log.i( TAG, "setupConnection AFTER" );
        }
    }
}

onResume()

public synchronized void onResume() {
    Log.i( "RESUME", "HERE" );
    super.onResume();
    if(D) Log.e(TAG, "+ ON RESUME +");

    Log.i( "RESUME", "AFTER HERE" );


    // Performing this check in onResume() covers the case in which BT was
    // not enabled during onStart(), so we were paused to enable it...
    // onResume() will be called when ACTION_REQUEST_ENABLE activity returns.
    if (mService != null) {
        // Only if the state is STATE_NONE, do we know that we haven't started already
        if (mService.getState() == BluetoothService.STATE_NONE) {
          // Start the Bluetooth chat services
          mService.start();
        }
    }
}

当你强行停止一个应用程序时,你会彻底杀死它并nothing生活。没有调用任何方法,什么也没有。这与系统终止应用程序以保留内存不同。 强制关闭并不意味着甜蜜,它的目的是杀死错误的应用程序,使其不再浪费。

因此,下次您打开应用程序时,它会从头开始 - MainActivity。这就是为什么强制停止“可能会导致应用程序行为不当”。您可能在做一些有用的事情时停止了它 - 例如写入服务器/文件系统等。这就是为什么您应该使您的应用程序尽可能高效或以可以处理意外关闭的方式对其进行编码。这可能意味着远离耗时的任务并快速且经常地进行储蓄。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“强制停止”将 Activity 留在其生命周期的哪个位置? 的相关文章

随机推荐

  • NSIncrementalStore 的简单英语解释

    我一直看到NSIncrementalStore当我一直在研究使用核心数据与 Web 服务交互的最佳方式时 这个问题就出现了 看完之后德鲁 克劳福德的文章 http sealedabstract com code nsincrementals
  • 有些控件没有绘制,看似随机

    我正在尝试为自己编写一个小 MFC 应用程序 以测试我正在训练的一些人工智能 因此 我添加了一个图片控件和一个静态控件 我可以在主窗口的 OnPaint 方法中自由地绘制内容 当只绘制一次应用程序时 它似乎可以工作 但我现在添加了一个在停止
  • 如何获取张量的值? Python

    在进行一些计算时 我最终计算出average acc 当我尝试打印它时 它输出 tf Tensor 0 982349 shape dtype float32 我如何获得0 98 它的值并将其用作普通浮点数 我想做的是将其中的一堆放在一个数组
  • 为什么标准输出不能被替换?

    出于教育目的 我尝试替换标准流 stdout stdin 和 stderr 我首先查找流的数据类型 我追溯到具有以下成员的 struct IO FILE gdb ptype IO FILE type struct IO FILE int f
  • FreeMarker 模板错误:以下内容已计算为 null 或缺失 |但事实并非如此

    我面临的错误是如此奇怪 一切看起来都很好 但是当浏览器向服务器发送 GET 请求时 我收到此错误 我想做的实际上是捕获 HTTP 参数 将它们保存在发送到 Freemarker 模板的 ArrayList 中保存的对象中 请你帮助我好吗 多
  • 计算 CRC 初始值而不是将 CRC 附加到有效负载

    我实现的大部分 CRC 都是追加计算出的 CRC 值到消息 有效负载 并在所有字节 包括 之后在接收器处检查零结果 CRC 值通过 CRC 寄存器输入 显然这是一个相当标准的方法 现在我想使用不同的方法 根据有效负载计算一个值 使用该值作为
  • 创建一个接受 POST 和 GET 的 Jax-RS RESTful 服务?

    我正在将现有的一项服务转变为 RESTful 并且我已经掌握了使用 RestEasy 的基本功能 我的一些客户端应用程序应该能够对多个服务执行 GET 和 POST 请求 我只是在寻找是否有任何简单的方法可以绕过 jax rs 来指定 AP
  • 我应该从 getFft 看到什么样的输出?

    好吧 我正在努力创建一个 Android 音频可视化应用程序 问题是 我从 getFft 方法中得到的结果与谷歌所说的它应该产生的结果不一致 我一直追溯到 C 源代码 但我对 C 或 FFT 不够熟悉 无法真正理解正在发生的事情 我将尝试包
  • sifr3 - 预取不起作用?

    我在启用 sifr 3 的网站的加载时间 大小方面遇到问题 并发现在我的应用程序中多次请求字体 swf 这可以在 firebug 的网络选项卡以及 apache 日志中看到 On http novemberborn net flash pr
  • 如何在Castle.DynamicProxy中使用IInterceptor?

    我写了一个这样的例子 简单计算器类 public class Calculator public int Add int a int b return a b 实现了DynamicProxy提供的 IInterceptor Serializ
  • 为什么“reset_index(drop=True)”函数会意外删除列?

    我有一个名为的 Pandas 数据框数据匹配 它包含 worker id unit id 和 caption 列 请参阅随附的屏幕截图 了解此数据框中的某些行 假设索引列不是按升序排列 我希望索引为 0 1 2 3 4 n 并且我希望它按升
  • 在 PubNub Swift 中访问 PNMessageResult

    请参阅此链接 http www pubnub com blog realtime ios apps getting started with swift and pubnub 基于以下功能我能够收到响应 func client client
  • Java MySQL 更新查询

    我收到错误 无法发出数据 这里是SSCCE package mysqltest import java awt import java awt event import javax swing import java applet Appl
  • 使用 Angular 5 分析 asp.net core 2(Web api)

    我正在寻找以下环境的分析解决方案 有人可以建议吗 net471 上的 ASP NET Core 2 实体框架 6 2 0 角度 5 0 0 我调查了迷你分析器 Glimpse Glimpse 尚未升级至 Core 2 0 MiniProfi
  • 实现最快运行时间的算法(问题、解决)

    对于算法竞赛训练 不是家庭作业 我们在过去一年中收到了这个问题 将其发布到此站点是因为其他站点需要登录 这就是问题 http pastehtml com view c5nhqhdcw html http pastehtml com view
  • 如何使用 NodeJS 创建流 API

    您将如何创建一个流 APINode http nodejs org 就像Twitter 流媒体 API http apiwiki twitter com Streaming API Documentation 我最终想做的是从FriendF
  • 如何克隆 Date 对象?

    分配一个Date变量到另一个变量会将引用复制到同一实例 这意味着改变一个就会改变另一个 我怎样才能真正克隆或复制Date实例 Use the Date https developer mozilla org en Core JavaScri
  • flutter android main 函数被调用两次

    在我的 flutter 应用程序中 我注意到 main 函数执行了两次 我正在使用计数器应用程序中的示例代码 文本main function被打印两次 我的 AndroidManifest xml 如下
  • 更改前缀后 npm 没有响应

    我最近尝试通过 npm 更新 IONIC CLI 安装成功了几次 但 CLI 版本没有改变 经过研究 我决定更改 npm 前缀 然后 IONIC strated 抛出 bash IONIC 命令未找到 然后我做了进一步的研究 之后我通过 w
  • “强制停止”将 Activity 留在其生命周期的哪个位置?

    假设我的应用程序已启动并正在运行 然后我进入我的设备主屏幕 导航设置 gt gt 应用程序 gt gt 管理应用程序 选择我的应用程序 然后按Force stop Which Activity下次打开应用程序时会调用方法吗 在我因不检查自己