在android studio的所有活动中保留帐户信息 [英] Keep the account info in all activities in android studio
问题描述
我的应用程序只是一个管理数据库应用程序.我设置了一个远程 mysql 服务器,我的 android studio 应用程序使用 http post 请求连接到该服务器.
My application is simply a managing database application. I have a remote mysql server set up and my android studio application uses http post request to connect to that server.
假设我想在所有活动中保留用户名、密码等帐户信息.现在我使用 putExtra() 在所有活动中传输和保留帐户信息,但这似乎很复杂.每次我开始一个新的活动并且我需要 putextra() 来传输我的帐户信息时,有没有更简单更好的方法来实现这一点?
Supposed I want to keep the account information like username, password in all activities. Right now I use the putExtra() to transfer and keep the account information in all activities but it seems complicated. Every time I start a new activity and I need the putextra() to transfer my account information, is there a easy and better way to accoumplish this?
推荐答案
多种选择:
1) 创建一个带有静态变量的全局类.
1) Create a global class with static variables.
2) 扩展 Application 类并在其中存储信息.
2) Extend the Application class and store information in it.
2) 如果只是两三个参数,可以存储在共享首选项中.
2) If it's just two-three parameters, you can store it in shared preferences.
这篇关于在android studio的所有活动中保留帐户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!