简体   繁体   English

无法从ApplicationAdapter调用Activity

[英]Can't call Activity from ApplicationAdapter

I'm starting on Android programming and right now I want to call an Activity from an ApplicationAdapter, but my code doesn't work. 我开始使用Android编程,现在我想从ApplicationAdapter调用Activity,但是我的代码无法正常工作。

I have this (ApplicationAdapter) class: 我有这个(ApplicationAdapter)类:

public class Render extends ApplicationAdapter implements SensorEventListener {
// ...
}

...and this (Activity) class: ...以及(活动)类:

public class GameOverActivity extends Activity {
//...
}

When, in the Render class I do: 什么时候在渲染类中执行:

Intent i = new Intent(Render.this, GameOverActivity.class);
startActivity(i);

I get this error in the first line: 我在第一行中收到此错误:

"Cannot resolve constructor 'Intent(......)' " “无法解析构造函数'Intent(......)'”

I tried to find another solutions but none of them worked. 我试图找到其他解决方案,但没有一个起作用。

Can anyone help me with this problem? 谁能帮助我解决这个问题?

使用context.startactivity(intent);

I managed to find an answer. 我设法找到答案。

In the Render class I did instance.startActivity(new Intent(instance, GameOverActivity.class)); 在Render类中,我执行了instance.startActivity(new Intent(instance, GameOverActivity.class)); and it worked just fine. 而且效果很好。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM