I have a method in which I'm fetching user's details and some data from firebase
database.
The problem is that the method is getting called twice or thrice after launching the app and again when I'm navigating back from any other activity.
I have put that method in onCreate
method like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
checkAuthState();
}
I am sure I haven't called checkAuthState()
in onStart()
or onResume()
methods.
This is how I'm navigating back from other activity:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
Please let me know why checkAuthState()
is getting called thrice and why it is getting called again when navigating back from any other activity and how to call this method only once when the app has been launched?
Sorry if question seems to be badly formatted. I'm still a beginner!
Create launcher activity to checkAuthStatus. Start a new activity and kill the launcher activity.