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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:52:02+00:00 2026-05-26T14:52:02+00:00

So, I’ll explain my situation. I have a Service which is catching the events

  • 0

So, I’ll explain my situation.
I have a Service which is catching the events from the power Button. In the service i have a broadcast receiver which takes Intent.ACTION_SCREEN_OFF and Intent.ACTION_SCREEN_ON.

// BroadcastReceiver for handling ACTION_SCREEN_OFF.
public BroadcastReceiver mReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        // Check action just to be on the safe side.
        if ((intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) ||
                (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) ) {

            if((System.currentTimeMillis() - delta) < DOUBLE_CLICK_INTERVAL) 
            {
                count++;
                Log.e("AAAAAAAA", "count= "+count);
            }else{
                count = 0;
            }

            if(count == 4){
                Log.e("AAAAAAAA", "EVENT TRIGGERED!!!!!");
                Intent alarmIntent = new Intent("com.myaction.action.EVENT_TRIGGERED");
                sendBroadcast(alarmIntent);
            }

            delta = System.currentTimeMillis();
        }
    }
};

I register the receiver in onCreate and i unregister it in onDestroy().
I have another BroadcastReceiver (this is registered in the manifest) which catch my action (EVENT_TRIGGERED). The broadcast receiver launch an activity that wraps a dialog.

public class AlarmBroadReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {

    Log.e("BROADCAST", "----------GOT THE EVENT---------");

    Intent newActivityDialog = new Intent(context, NotifyDialog.class);
    newActivityDialog .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(newActivityDialog );

}}

The Activity called by the broadcast is the following:

public class NotifyDialog extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Log.e("DIALOGACTIVITY", "ON CREATE");
    final Window win = getWindow();
    win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                  | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); 
    win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                  | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);




}



@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    Log.e("DIALOGACTIVITY", "ON START");
    displayAlert();
}





@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    Log.e("DIALOGACTIVITY", "ON RESUME");
}





@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    Log.e("DIALOGACTIVITY", "ON PAUSE");
}


@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    Log.e("DIALOGACTIVITY", "ON DESTROY");
}





private void displayAlert()
{
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Random question?").setCancelable(
            false).setPositiveButton("Yes",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    //do somethin

                    dialog.cancel();
                    finish();
                }
            }).setNegativeButton("No",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    finish();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}}

When i push (several times) the power button, my action is broadcast and caught by the proper receiver which launch the activity. My problem is that the activiy is called twice and i dont get the reason, the log gives an idea of what happen:

11-04 16:20:22.339: E/AAAAAAAA(19451): count= 1
11-04 16:20:22.562: E/AAAAAAAA(19451): count= 2
11-04 16:20:22.886: E/AAAAAAAA(19451): count= 3
11-04 16:20:22.983: E/AAAAAAAA(19451): count= 4
11-04 16:20:22.983: E/AAAAAAAA(19451): EVENT TRIGGERED!!!!!
11-04 16:20:23.073: E/AAAAAAAA(19451): count= 5
11-04 16:20:23.077: E/MAMT FESC(19451): ----------GOT SOMETHING---------
11-04 16:20:23.085: E/DIALOGACTIVITY(19451): ON CREATE
11-04 16:20:23.085: E/DIALOGACTIVITY(19451): ON START
11-04 16:20:23.112: E/DIALOGACTIVITY(19451): ON RESUME
11-04 16:20:23.499: E/DIALOGACTIVITY(19451): ON PAUSE
11-04 16:20:23.499: E/DIALOGACTIVITY(19451): ON DESTROY
11-04 16:20:23.554: E/WindowManager(19451): Activity com.notfall.NotifyEmergencyCall has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@482c8228 that was originally added here
11-04 16:20:23.554: E/WindowManager(19451): android.view.WindowLeaked: Activity com.notfall.NotifyEmergencyCall has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@482c8228 that was originally added here
11-04 16:20:23.554: E/WindowManager(19451):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
11-04 16:20:23.554: E/WindowManager(19451):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:181)
11-04 16:20:23.554: E/WindowManager(19451):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:124)
11-04 16:20:23.554: E/WindowManager(19451):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.Dialog.show(Dialog.java:241)
11-04 16:20:23.554: E/WindowManager(19451):     at com.notfall.NotifyEmergencyCall.displayAlert(NotifyEmergencyCall.java:115)
11-04 16:20:23.554: E/WindowManager(19451):     at com.notfall.NotifyEmergencyCall.onStart(NotifyEmergencyCall.java:54)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.Activity.performStart(Activity.java:3781)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-04 16:20:23.554: E/WindowManager(19451):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-04 16:20:23.554: E/WindowManager(19451):     at android.os.Looper.loop(Looper.java:123)
11-04 16:20:23.554: E/WindowManager(19451):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-04 16:20:23.554: E/WindowManager(19451):     at java.lang.reflect.Method.invokeNative(Native Method)
11-04 16:20:23.554: E/WindowManager(19451):     at java.lang.reflect.Method.invoke(Method.java:521)
11-04 16:20:23.554: E/WindowManager(19451):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-04 16:20:23.554: E/WindowManager(19451):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-04 16:20:23.554: E/WindowManager(19451):     at dalvik.system.NativeStart.main(Native Method)
11-04 16:20:23.554: E/DIALOGACTIVITY(19451): ON CREATE
11-04 16:20:23.558: E/DIALOGACTIVITY(19451): ON START
11-04 16:20:23.620: E/DIALOGACTIVITY(19451): ON RESUME
11-04 16:20:23.636: E/DIALOGACTIVITY(19451): ON PAUSE
11-04 16:20:23.815: E/DIALOGACTIVITY(19451): ON RESUME
11-04 16:20:24.105: E/AAAAAAAA(19451): count= 1
11-04 16:21:19.589: E/DIALOGACTIVITY(19451): ON PAUSE
11-04 16:21:19.667: E/DIALOGACTIVITY(19451): ON DESTROY

My guess is the window leak is caused by the double call to the activity. And as you can see the broadcast is sent and received only once. Sorry for the long mail but i had to explain the whole situation in order to you guys understand why the activity is called twice. Thanks guys.

Daniel

  • 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-26T14:52:03+00:00Added an answer on May 26, 2026 at 2:52 pm

    I’m not sure why your activity is getting started twice, but you can remove the leak by clearing up the dialog. Make the dialog a member variable of the Activity, and dismiss and null it onStop if it exists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.