Where to put Firebase.setAndroidContext() function

后端 未结 6 1469
长发绾君心
长发绾君心 2020-12-20 15:57

I\'m trying to play a bit with Firebase and Android.
I have one RegisterActivity, and one MainActivity. My current flow is - start with M

6条回答
  •  天命终不由人
    2020-12-20 16:32

    I do not know FireBase but i know Android.. A Context is a global information about an application environment. Your Activity is a Context so i am pretty sure Firebase.getAndroidContext() retrieves your Application Context which is getApplicationContext(), Since that seems sensible.

    Should I only call this function once in Application or once in each Activty?

    call it whenever you need a Context with respects to FireBase codes- but i think will suit best if you call it in your Application class

    If the answer for question 1 is only once, then where should I put it ?

    what if its not once? where do you call it? i guess you will call it anywhere you need Context right? so do that irrespective of question 1's answer, but you can fall on Class.this , getBaseContext() or View.getContext() anytime

提交回复
热议问题