简体   繁体   English

来自其他活动的方法不是来自另一个活动的调用

[英]Method from other activity is not Calling from another activity

I am trying to Call method from Another Activity but it is not calling. 我正在尝试从“ 另一个活动”中调用方法,但未调用。 When i use intent it works but when i call method it fails. 当我使用意图时,它可以工作,但是当我调用方法时,它会失败。 The method which is in onNotificationPosted() . onNotificationPosted() Here is the code 这是代码

public class NotificationListener extends NotificationListenerService {

    Context context;
    private DatabaseReference dbref;
    private FirebaseAuth mAuth;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        dbref= FirebaseDatabase.getInstance().getReference();
        mAuth=FirebaseAuth.getInstance();
    }

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        ChatActivity ch=new ChatActivity();
        ch.location();
      //  Intent n=new Intent(NotificationListener.this,ChatActivity.class);
        //startActivity(n);
    }

    @Override
    public void onNotificationRemoved(StatusBarNotification sbn) {
        Log.i("Msg","Notification Removed");
    }
}

The intent which is commented works but the method is not calling. 注释的意图有效,但该方法未调用。 Please help me. 请帮我。 Thanks in advance. 提前致谢。

使该方法静态,然后像调用它一样

ChatActivity.ch();

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

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