[英]Android send extra Data through multiple Activities
I have a chain of intents 我有一连串的意图
1) Select File 1)选择文件
2) Overlay some stuff 2)覆盖一些东西
3) Save on Disk 3)保存在磁盘上
4) Upload to Server 4)上传到服务器
This means that i am using those commands 4 times: 这意味着我正在使用这些命令4次:
video_id = extras.getString("video_id");
i.putExtra("video_id", video_id);'
Is there another neat way of doing that, without having to write anything on disc or db? 还有另一种整齐的方法,而不必在磁盘或db上写任何东西吗?
You can use Singleton Class ie Application in android. 您可以使用Singleton类,即android中的Application 。 It maintains global application state.
它维护全局应用程序状态。
public class GlobalClass extends Application{
private String name;
public String getName() {
return name;
}
}
Assign GlobalClass.java in application tag in application Manifest.xml android:name="com.androidexample.globalvariable.GlobalClass"
在应用程序Manifest.xml
android:name="com.androidexample.globalvariable.GlobalClass"
应用程序标记中分配GlobalClass.java
After Assigning you can set or access this variable from any activity using following code. 分配后,您可以使用以下代码在任何活动中设置或访问此变量。
final GlobalClass globalVariable = (GlobalClass) getApplicationContext();
//Set name in global/application context
globalVariable.setName("Android Example context variable");
//get name frim global/application context from any other activity.
String name = globalVariable.getName();
Use SharedPreference. 使用SharedPreference。 Please check http://developer.android.com/training/basics/data-storage/shared-preferences.html SharedPreference will not delete automatically.
请检查http://developer.android.com/training/basics/data-storage/shared-preferences.html SharedPreference不会自动删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.