亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

android - Home鍵返回主界面之后,點擊ICON再次喚起應(yīng)用時又重新啟動了APP
天蓬老師
天蓬老師 2017-04-17 17:37:55
0
8
1156

如題:
我現(xiàn)在簡單的做了個測試的APP,整個測試流程如下:
1、點擊ICON啟動APP運行MainActivity.java主界面;
2、點擊按鈕跳轉(zhuǎn)到BActivty.java界面,此時MainActivity沒有使用finish(),在BActivity.java中點擊按鈕獲取數(shù)據(jù)顯示到 BActivity界面上;
3、然后點擊Home鍵回到手機的主界面;
4、再次點擊應(yīng)用程序的圖標(biāo),然后就重新啟動了APP。
我現(xiàn)在想要在點擊ICON的時候回到BActivity退出時的狀態(tài)該怎么做?新手還請指教!
測試始終發(fā)現(xiàn)每次都是重新啟動了APP,網(wǎng)上有的說加下面一段代碼在根Activity就可以,
但是我使用了,表面上是回到了之前的界面,但是事件操作會出錯。

    if (!isTaskRoot()) {
        finish();
        return;
    }

在線等,希望各位指點,先謝謝了。

簡單點說就是我按Home鍵返回了桌面,我要點擊ICON怎么返回之前的狀態(tài)。

最奇怪的就是在開發(fā)環(huán)境下launch運行到手機中,使用Home返回桌面,再次點擊應(yīng)用程序就是可以返回之前的狀態(tài)的,多次測試都是正常的;但是當(dāng)我打包簽名之后,發(fā)送到手機上使用這個簽名的APK來測試就會出現(xiàn)每次點擊應(yīng)用程序圖標(biāo)都會運行MainActivity,之前的界面就在這個MainActivity之下,即結(jié)束這個MainActivty就會出現(xiàn)之前的界面。
啟動多少次就要多少了MainActivity,我也是醉了啊~~~~就是返不回之前的狀態(tài)。

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進步~~

reply all(8)
Peter_Zhu

Under normal circumstances, the Home key will not exit the application. Try changing your phone. It is possible that your phone has low memory, so it will be destroyed.

伊謝爾倫

Under normal circumstances, the situation you described will not occur. First you should print the life cycle of BActivity. You can change to several more models. It is recommended to use the following two methods onSaveInstanceState() and onRestoreInstanceState() in A

左手右手慢動作

It is recommended to try a test machine with a higher configuration. It should be killed because the system memory is tight. If this is the case, then the problem should be changed to how to implement the keep-alive mechanism, or you can try to reduce your own memory usage.

PHPzhong

Has your MainActivity set up a singleTask?

洪濤

Set the launchMode of MainActivity to SingleTask

阿神

Isn’t it very unskilled? Big brothers, please help the younger ones

迷茫

Did it work out, man

黃舟

This problem should occur during the first installation, right?
Add the following code to your launchActivity onCreate method:

/**
 * 解決APP打包第一次安裝之后啟動APP圖標(biāo)會出現(xiàn)多個程序的問題
 */
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
    finish();
    return;
}

Hope it helps you!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template