Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6852967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:27:18+00:00 2026-05-27T01:27:18+00:00

The Plan: I’m developing an android application that is heavily database driven (as in,

  • 0

The Plan:

I’m developing an android application that is heavily database driven (as in, most of the content is fetched from a MySQL database via a RESTful service layer on my webserver).

Before any calls can be made to the API requesting data, the user has to b authenticated by passing his credentials where they are checked against the database. If the user is validated, I pass back an authorization token. If the user selected the ‘Remember Me’ option, this token will be saved locally for future use.

All future API calls need to contain this authorization token.

When the user wishes to logout, a call is sent back to the API to delete that token from the database, thereby invalidating it for future use. Local copy of the token is deleted as well.


The Issue

If the user does not logout, and simply closes the app (Home or back button) and did not have the ‘Remember Me’ option selected, I want to destroy the token at the server. How can this be done?


Possible Solutions #1

  • If there is an onExit event that fires when the application exits, make a call to the API letting it know to destroy the token.

Problems with this method are:

  • Does such an event exist, which is guaranteed to be raised in all
    conditions (home button, back button, program crash (I can live
    without this one) )?

Possible Solutions #2

  • Maintain a time of last activity column in the database. If a call is made x min since the last activity, the token will be considered expired.

Problems with this method are:

  • Added overhead of updating the time column in the database on every API call.

  • Additionally, I will now have to store in the database if the user selected to be remembered, because in that situation the token cannot expire.


Which of the two solutions would you implement? Or is there another, better, way to implement this mechanism?

If you suggest #1, please advise which event it is that will serve my purpose.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:27:18+00:00Added an answer on May 27, 2026 at 1:27 am

    Your first solution is not applicable because:

    1. There are no onExit event. (Of course you can create base activity and monitor there if the user pressed Home or back button just to figure out if the user hide the application or not. But that’s very very complicated)
    2. Do not rely on client logout. What if the user requested logout but the internet was not available at that time?
    3. Android can simply kill your application at any time in low memory situation.

    You’d better implement the second solution. Positives:

    1. AFAIK, it’s common practice when server controls the expiration of authorization token
    2. No need to store in the database if the user selected to be remembered. Simply set expiration date to Integer.MAX_VALUE or something.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I plan to develop Android application which will encrypt/decrypt voice data such that parties
I plan to translate an .net 2.0 application to different languages. For that I
I plan to build a WinForms application that will contain among other controls a
I plan to be storing all my config settings in my application's app.config section
We plan to redesign, improve our (C#) application architecture. Anyone has some framework, hompage
I plan to use dojo.query to get some elements by their name attribute from
I plan to make an web application using XPages for the design (plus the
I plan to provide content/services across multiple (similar and related) subcategories. In general, users
I plan to skip the block content which include the start line of MaterializeU4()
My plan is to make a function that retrieves the highest element of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.