I am using an event listener in my main activity to determine network connectivity with the database
//Main Activity
new MyListener() {
if (connected) {
Log.d(TAG,"connected");
Snackbar.make(_current_view_,"Connected to Firebase", Snackbar.LENGTH_SHORT).show();
}
else {
Log.d(TAG,"disconnected");
Snackbar.make(__current_view_, "Disconnected from Firebase", Snackbar.LENGTH_SHORT).show();
}
});
Now, since this is a listener in the main activity, every time network connectivity changes, this gets elegantly called. But I need a view of the current activity being rendered by the Application.
How do I get the current view? The listener works and the logging is perfect but the Snackbar is not called, because we are not on the layout of the main activity. When we are though, the snackbar gets displayed. Is it possible to get the reference of current view?
When I replace SnackBars with Toasts, they work in tandem with the log perfectly.
Toast.makeText(Login.this, "Connected to Firebase", Toast.LENGTH_SHORT).show(); //Works
I tried:
getCurrentFocus()
findViewbyId(android.R.id.content)
getWindow().getDecorView()
getWindow().getDecorView().getRootView()
None, of which works. Any help would be appreciated.