android-how to make a login? -


i've information in application , it's company information . want make login every time app closes , runs .

this i've done far . make custom dialog user , password field . problem , every time rotate screen or come mainactivity , need re login , it's bothering alot .

i want dialog comes every time close app , run again , . i've tried onstop , ondestory when rotate screen or change activity , leave mainactivity , show me dialog .

how can show dialog first time app runs , if close app , run again ,it asks me login again ?

thanks

on orientation change, life cycle functions of activity called, because reconstructed zero. application must take account. current activity goes onpause() onstop() ondestroy(), new activity goes oncreate() onstart() onresume(), in order.

therefore must store fact have logged in, in such way application not forget. peristent data storage can done sharedpreferences example, if don't want use more complicated. check out android getdefaultsharedpreferences this.

what (but seems haxory solution rather one) in onsaveinstancestate(bundle bundle) function save out current value of boolean indicates being logged in bundle, , in ondestroy() set false in sharedpreferences. in oncreate(bundle bundle) function, if bundle isn't null, update sharedpreferences' boolean according bundle's content. if user "logged in" according boolean, don't display dialog.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -