gpt4 book ai didi

android 新 Intent 错误

转载 作者:行者123 更新时间:2023-11-29 15:26:00 24 4
gpt4 key购买 nike

我是 android 新手,我尝试在两个 Activity 之间传输数据。Eclipse 告诉我这一行:

Intent i = new Intent(this, PostDataActivity.class);

构造函数 Intent 未定义。我能做什么?

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

btnShowLocation = (Button) findViewById(R.id.ansehen);

// show location button click event
btnShowLocation.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
// create class object
gps = new GpsData(StartActivity.this);

// check if GPS enabled
if(gps.canGetLocation()){

double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
String mlat = String.valueOf(latitude);

// \n is for new line
Intent i = new Intent(this, PostDataActivity.class);
i.putExtra("Value1", "This value one for ActivityTwo ");

最佳答案

您正在尝试从 OnClickListener 中初始化您的 Intent。因此,您传递给构造函数的 this 参数指的是监听器,而不是您的 Activity。

要解决问题,请使用:

Intent i = new Intent(YourActivityName.this, PostDataActivity.class);

关于android 新 Intent 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12954890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com