简体   繁体   English

如何使用Application类将数据从一个活动传递到另一个活动

[英]how to pass data from one activity to another activity with th use of Application class

import android.app.Application;

public class MyData extends Application{
private String name;
private String phone;
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getPhone() {
    return phone;
}
public void setPhone(String phone) {
    this.phone = phone;
}
}

When I am using following line of code in caller Activity to send data, I get a ClassCastException: 当我在调用者Activity中使用以下代码行发送数据时,我得到一个ClassCastException:

MyData data=(MyData)getApplication();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Android应用程序中将数据从一项活动传递到另一项活动 - How to pass data from one activity to another in Android application 如何将ArrayList中的类从一个活动传递给另一个活动 - How to pass Class of Class in ArrayList from one Activity to Another Activity 如何从一个活动的列表视图传递数据并将其传递给另一活动? - How to pass the data from listview of one activity and pass it to another activity? 我如何将数据从一个活动传递到另一活动 - how i pass data from one activity to another activity 如何将数据从一个活动传递到另一活动 - How to pass data from one activity to another activity 如何将数据从一个活动传递到 Android 中的另一个活动 - How to pass data from one activity to another activity in Android 如何将图像数据从一个活动传递到另一个活动? - How to pass image data from one activity to another activity? 如何使用SharedPreferences将数据从活动传递到另一个活动 - how to use SharedPreferences to pass data from activity to another activity 如何将数据从活动传递到另一个活动,然后再传递到Android上的另一个活动? - How to pass data from an activity to another activity and then to another activity on Android? 如何传递ArrayList <Class> 从一项活动到另一项活动? - How to pass ArrayList<Class> from one activity to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM