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 6932409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:42:09+00:00 2026-05-27T11:42:09+00:00

In my application I let user to buy application based of different plans, such

  • 0

In my application I let user to buy application based of different plans, such as 2 hours free, 1 day, 1 week, and etc.

I want to don’t let user use the application after expiry time. I created a service and set alarm in main activity and in service I have told that after expiry time open main activity.

The code of setting alarm in main activity:

private void updateService(){
        Intent myIntent = new Intent(DRMActivity.this, AlarmService.class);
        pendingIntent = PendingIntent.getService(DRMActivity.this, 0, myIntent, 0);

        AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.SECOND, 30);
        alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);

        Toast.makeText(DRMActivity.this, "Start Alarm", Toast.LENGTH_LONG).show();
    }

The code of service:

@Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);

        Intent myIntent = new Intent(getBaseContext(), DRMActivity.class);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Toast.makeText(this, "AlarmService.onStart()", Toast.LENGTH_LONG).show();

        getApplication().startActivity(myIntent);
    }

So far everything is OK, even if my main activity is destroyed, service can run it again. But I think in android, unfortunately, application is built from several activities, therefore, from an activity we can’t stop the application. What I mean?
We have finish() method which will terminate the activity but it can’t close the whole of application. Therefore, after terminating an activity of application, previous activity of that application will show.

So, back to my story. after for example 30 seconds (according to above code) service will run my main activity. But what will happen if user easily click back button? s/he can come back to previous activity of application and continue his usage.

One good suggestion is creating shared preferences and in service I change a flag and in onStart() of each activity I check it. I think it works but the bad thing is I am working on a wrapper that it should be add to other projects and I can’t ask other developers to add this or check that.

What is your suggestion? is there anyway to don’t let user to continue using application after expiry time?

=======>
UPDATE:

For future reference. I Used FLAG_ACTIVITY_CLEAR_TOP and the problem is solved. Now, even user clicks back button all activities between Main activity and Last activity will clear. According to its documentation:

If set, and the activity being launched is already running in the
current task, then instead of launching a new instance of that
activity, all of the other activities on top of it will be closed and
this Intent will be delivered to the (now on top) old activity as a
new Intent.

For example, consider a task consisting of the activities: A, B, C, D.
If D calls startActivity() with an Intent that resolves to the
component of activity B, then C and D will be finished and B receive
the given Intent, resulting in the stack now being: A, B.

  • 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-27T11:42:09+00:00Added an answer on May 27, 2026 at 11:42 am

    Three possibilities:

    1. Override onBackPressed() to do nothing.
    2. Remove that Activity from the back stack altogether by adding a flag for FLAG_ACTIVITY_NO_HISTORY to the Intent that originally started it.
    3. Commit some data to SharedPreferences and check for it in onResume when user goes back. If the data says it’s expired, then disable whatever functionality you want to.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If we want in our WPF application to let a user make a SQL
I want to let application user know that whom buddy has downloaded the application
In my GTK+ application, I want to show an image and let the user
I want let user mark their position in our google maps application and then
I have a simple application in which I need to let the user select
I'm developing a C# web application in VS 2008. I let the user select
Let's say that I have an application frame, and I want to show a
I want to ask a question about the iPhone application. The application can let
My application uses Identity claim authentication (Active directory user account) to let user access
Currently, I have an application, which will save a temporary screenshot, and let user

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.