如何从一个活动调用另一个活动中定义的方法
这是我的 Activity 类
public class A extends Activity
{
.......
.......
//here i have to call my test() method of B activity
new B.test();
}
这是我的下一个 Activity
public class B extends Activity
{
......
public void test(){
//some code }
}
但 test() 方法并未执行。我在 test() 方法中放置了一条 Toast 消息。但它没有显示 Toast 消息。如何调用该 test() 方法。我哪里错了?我是否必须重写 B 活动中的 onCreate() ?请告诉我。提前致谢。
Here is my Activity class
public class A extends Activity
{
.......
.......
//here i have to call my test() method of B activity
new B.test();
}
This is my next Activity
public class B extends Activity
{
......
public void test(){
//some code }
}
But the test() method is not not executing. I put a Toast message in test() method. but it is not showing the Toast message. How to call that test() method. Where am I wrong? Do i have to override onCreate() in B activity? Please tell me. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在不扩展 Activity 的单独类中编写测试方法。这样您就可以在需要时从两个 Activity 调用该方法。
Activity是一个不同的屏幕,你可以通过意图调用它,以便它可以显示在屏幕上
You can write test method in separate class which doesn't extends Activity.So that you can call the method from two activities whenever you need.
An activity is a different screen and you can call it by intent,so that it can be shown on screen
这样做。
和
Do this.
and