Home > Java > javaTutorial > How to Implement Logout and Clear Previous Activities in Android 1.6?

How to Implement Logout and Clear Previous Activities in Android 1.6?

Susan Sarandon
Release: 2024-11-03 18:52:29
Original
613 people have browsed it

How to Implement Logout and Clear Previous Activities in Android 1.6?

Finishing Previous Activities on Logout

In an Android application navigating through multiple screens (Home to Screen 5), the requirement is to implement a logout button on each screen that, when clicked, terminates all previous activities and opens a Login screen.

The FLAG_ACTIVITY_CLEAR_TASK flag, which would have been an ideal solution, is unavailable in Android 1.6. However, there is an alternative approach:

  1. Create an Intent for the Home screen activity:

    <code class="java">Intent intent = new Intent(getApplicationContext(), Home.class);</code>
    Copy after login
  2. Add the FLAG_ACTIVITY_CLEAR_TOP flag to the Intent:

    <code class="java">intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);</code>
    Copy after login
  3. Start the Activity:

    <code class="java">startActivity(intent);</code>
    Copy after login

The FLAG_ACTIVITY_CLEAR_TOP ensures that all activities above the Home screen are cleared, effectively returning the user to the Home screen.

If the Login screen needs to be launched directly, you can include an extra in the Intent and check for it in the Home screen activity. Depending on the specific scenario, you may need to finish the Home screen activity as well.

The above is the detailed content of How to Implement Logout and Clear Previous Activities in Android 1.6?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template