-3

I cannot call method from another activity in OnNotificationPosted. I also tried to make instance of activity but failed. I searched alot but no success. please help

NotificationListener

public class NotificationListener extends NotificationListenerService {
    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        otherActivity oth = new otherActivity();
        oth.loc();
    }

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

otherActivity

public class OtherActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_other);

    }

    public void loc() {
//code body
    }
}
Saif Ahmad
  • 1,118
  • 1
  • 8
  • 24

1 Answers1

0
public class OtherActivity extends AppCompatActivity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_other);

        }

          public static void loc(){
                //code body 
            }

    }

how to using : otherActivity.loc();

public class NotificationListener extends NotificationListenerService {
@Override
public void onCreate() {
    super.onCreate();
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
   otherActivity.loc();

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