'Broadcast receiver with activity inheritance
I have a question. I have 2 activities in each I initialize the broadcast receiver to obtain internet connection changes. After changes are received, I notify the user about it by displaying some text on the screen.
In order not to write the code several times, I created BroadcastActivity that inherits from AppCompatActivity.
Now I pass views with super() to BroadcastActivity and manipulate with views (Change texts, visibilities etc.).
Question is: Is it best practice to do so or is there a more elegant solution? And if it can lead to memory leaks?
Thank you for your help!
Example of BroadcastActivity
open class BroadcastActivity : AppCompatActivity(), OnConnectionChangeListener {
//some code
}
And example of activity (Secondary activity structure similar to this)
public class MainActivity extends BroadcastActivity{
//some code
}
P.S. BroadcastActivity written on Kotlin and MainActivity on Java.
P.S. 2 At this moment I can't switch to single activity and looking for temporary solution.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
