如何节省后退按钮preSS应用按钮、节省、preSS

2023-09-07 22:01:25 作者:穿着凉鞋闯江湖

我如何保存我的应用程序的状态时,返回键为pressed。

How can I store the state of my app when back button is pressed.

在后退按钮是pssed仅的onPause()的调用,但没有的onSaveInstanceState 在这里我们可以存储$ P $我们在outState捆绑数据。

When back button is pressed only onPause() is called but not onSaveInstanceState where we can store our data in outState bundle.

一个答案可能是共享preference ,但我的问题是,它会只存储int和不 intArray 作为包一样。

One answer may be sharedPreference but my problem is it will store only int and not intArray as bundles does.

有什么办法明确调用的onSaveInstanceState

推荐答案

用户600027 ...即使你能叫的的onSaveInstanceState束不会坚持,我不相信一个硬杀伤后,这将是可用。你可以写一个方法来转换成整数设置字符串数组,然后通过调用putStringSet(),然后持续数据写入的方法,以一组字符串隐蔽到int数组。

user 600027... Even if you were able to call onSaveInstanceState the bundle would not be persisted and I do not believe it would be available after a hard kill. You could write a method to convert an array of ints to set of strings and then persist the data by calling putStringSet() and then write a method to covert a set of strings to an array of ints.

JAL