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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:23:38+00:00 2026-05-28T13:23:38+00:00

I have a broadcast receiver which will launch an Activity onReceive. When launched, this

  • 0

I have a broadcast receiver which will launch an Activity onReceive.

When launched, this activity will perform a long task and call finish() at the end.

I do not want to trigger another launch of Activity when the previous Activity is still performing the long task. How can I launch only a singletask activity? I have set this in the manifest.

android:launchMode="singleTask"

In my onReceive method,

public void onReceive(Context context, Intent intent) {
    Intent activity = new Intent(context, Preview.class);
    activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(activity);
}

Don’t seems to work.

The Activity class actually is a MediaRecorder which will record a video clip (say 10 sec). Thus I do not want to trigger another Activity while this recording is still incomplete.

  • 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-28T13:23:39+00:00Added an answer on May 28, 2026 at 1:23 pm

    You just need to have some way for your activity to communicate to your receiver to let it know whether or not it is already running. If you have that then you can make an if statement in the receiver that will keep it from launching multiples.

    One option is a static boolean in your activity that indicates whether or not you are currently running. Then you can check that boolean from the receiver, and if it is true, then don’t call startActivity().

    your activity would need something like this:

    public YourActivity extends Activity{
        public static isRunning = false;
        public void onStart(){
            ...
            isRunning = true;
        }
        public void onStop(){
        ...
            isRunning = false;
        }
    }
    

    now in your receiver you can make a simple if statement that will check the value of isRunning:

    public void onReceive(Context context, Intent intent) {
        if(YourActivity.isRunning == false){
            Intent activity = new Intent(context, Preview.class);
            activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(activity);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a broadcast receiver which I want to pass onto an activity but
I have written PhoneStateListener which listens for telephony events through broadcast receiver. I am
I have a simple broadcast receiver which receives some data which I would like
I have a particular situation: a service started by a broadcast receiver starts an
I have an Android Service. When a phone boots up, a broadcast receiver receives
Hello I faced the same problem I have 1 broadcast receiver from that I
In my application, I have registered a broadcast receiver to receive the system intent
I have a broadcast reciever triggered by an alarm event, which checks if the
I am building an application in android, which will perform an action when any
In my app I have a broadcast receiver that turns on GPS upon receiving

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.