Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将值从一个屏幕传递到另一个屏幕_Android_Android Intent_Android Activity - Fatal编程技术网

Android 将值从一个屏幕传递到另一个屏幕

Android 将值从一个屏幕传递到另一个屏幕,android,android-intent,android-activity,Android,Android Intent,Android Activity,历史在我的项目中,我有大约30个不同的屏幕来获取数据。 现在,我通常需要将值从一个屏幕传递到另一个屏幕。(如UserID、StoreID、City等) 我当前传递值的操作。我连续做了30个屏幕 //Sender Activity String strValue = "xyz"; Intent i = new Intent(this, ToClass.class); i.putExtra("strValue", strValue); startActivity(i); //Recei

历史在我的项目中,我有大约30个不同的屏幕来获取数据。 现在,我通常需要将值从一个屏幕传递到另一个屏幕。(如UserID、StoreID、City等)

我当前传递值的操作。我连续做了30个屏幕

//Sender Activity
String strValue  = "xyz";    
Intent i = new Intent(this, ToClass.class);
i.putExtra("strValue", strValue);
startActivity(i); 

//Receiving Activity
Intent intent = getIntent();
String strValue= intent.getExtras().getString("strValue");
现在我的技术问题是
a) 发送方活动中仍处于活动状态(或使用内存)的值。那么,在进行下一项活动时,如何清除 b) 我是否应该在需要时在
DB
中保存
strValue
值并从
DB
访问值?因此节省了我的记忆。
c) 这是安卓系统中最好的方法吗。我当前使用的。

a)将内存/数据的清除留给GC,它将处理内存中未使用的数据

b) 如果它只是一个值,你不想把它放在
DB
中,因为它也会使用
内存
,而且需要更长的时间(就
ms
而言,我认为/开销而言),而不是将其作为捆绑包或共享引用传递


c) 如果您希望您的
strValue
仅在应用程序处于活动状态时才处于活动状态。这就是你的方法。如果您希望
strValue
在内存中,我假设您只能使用1个值。如果你有这么多的数据,你需要把它放在内存中,那就是使用它的时候了

您可以在内存中保存数据。这是最好的方法,因为清除数据时会删除该数据。在DB中保存和检索将增加cpu开销。您可以在调用
startActivity()
后调用
finish()
。另一个选项是,如果活动正在完成,则将值指向
null
。因此,在
onPause()
中检查您的活动是否正在完成,并执行
strValue=null看看讨论Java性能调优的线程。