简体   繁体   English

我想在应用程序重新启动后将 Cookie 永久存储在我的 Android 应用程序中以使用用于 rest api 调用的 cookie (HttpUrlConnection)

[英]I want to store the Cookie permanently in my Android App after the app restart to use the cookie for rest api call (HttpUrlConnection)

I have used '''CookieManager cookieManager = new CookieManager();我用过'''CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager);''' CookieHandler.setDefault(cookieManager);'''

It is working fine but when the app restart the cookie gets deleted and i cant used it for further rest calls.它工作正常,但是当应用程序重新启动时,cookie 被删除,我无法将其用于进一步的 rest 调用。

There are multiple ways using which you can save data permanently (until you can'y clear app data).您可以通过多种方式永久保存数据(直到您可以清除应用数据)。

  1. SharedPreference共享偏好
  2. Local Database (SQLite / Room - Recommending)本地数据库(SQLite / Room - 推荐)

Using above listed methods you can store you data and also get those data after restart of application/mobile phone.使用上面列出的方法,您可以存储数据并在重新启动应用程序/手机后获取这些数据。

You can get an idea of access of above listed methods using below links.您可以使用以下链接了解上述方法的访问方式。

  1. SharedPreference: https://www.tutorialspoint.com/android/android_shared_preferences.htm SharedPreference: https://www.tutorialspoint.com/android/android_shared_preferences.htm

  2. SQLite: https://www.geeksforgeeks.org/how-to-create-and-add-data-to-sqlite-database-in-android/ SQLite: https://www.geeksforgeeks.org/how-to-create-and-add-data-to-sqlite-database-in-android/

  3. Room: https://www.geeksforgeeks.org/how-to-perform-crud-operations-in-room-database-in-android/房间: https://www.geeksforgeeks.org/how-to-perform-crud-operations-in-room-database-in-android/

Thank you.谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Cookie被拒绝进行Rest API调用 - Cookie Rejected For Rest API call 如何创建cookie并在HttpURLConnection中使用它? - How to create a cookie and use it in HttpURLConnection? httpClient无法在我的android应用中保留具有许多异步请求的cookie - httpClient can not retain cookie with many async request in my android app 从SharedPreference向Android应用程序中的Cookie Manager添加Cookie - Adding Cookie to Cookie Manager in android app from SharedPreference 我想从应用商店和谷歌播放(以编程方式)获取我的应用的安装计数,是否有官方 api - I want to get count of installations for my app from app store and google play (programmatically), is there an official api (Android)HttpClient,URL和HttpURLConnection中的Cookie问题 - (Android) Cookie problems in HttpClient, URL and HttpURLConnection Android Studio应用更改询问我是否要重新启动应用 - Android Studio Apply Changes asks if I want to Restart App Android中的Http cookie商店 - Http cookie store in Android android应用中http响应中缺少cookie - Missing cookie in http response in android app 被杀死后重新启动应用程序时出现致命异常(android) - Fatal exception when I restart my app after it's been killed (android)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM