How to start activity from and in a broadcast receiver in android?

    1 answer 1

    Very simple.

    1. When the broadcast receiver triggers, its onReceive method will be called.
    2. In this method, and run the actiniti in the usual way.
    startActivity(new Intent(this, MainActivity.class)); 
    • Are there ways to transfer data to an activity without displaying it? - evgeniy.se
    • @ evgeniy.se, explain. Why do you need to activate it if you do not need to display it? Use the service. - Yuriy SPb
    • Now in Broadcast I receive messages (from the server). I wrote an interface in which one function was declared. The message came. The interface implements the activation. In the public Broadcast method, I initialize the interface and when I receive a message in onReceive (), I call the interface method on the activity. I now have the task to remove the interface. I'm looking for options like this is done in standard android ways. - evgeniy.se
    • @ evgeniy.se, well ... You can implement the interface in the receiver. Or implement it at all in a separate class and create an instance of this class in the activit ...
    • one
      It all depends on the implementation. So far, it is not very clear what and why you are doing - YuriySPb