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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:01:11+00:00 2026-05-17T15:01:11+00:00

I am writing an android app to give the user the option to call

  • 0

I am writing an android app to give the user the option to call a different alternative number based on the number he tried to call.
To do that I have BroadCastReceiver that gets the number being called, checks if there are alternatives and then to show the dialog it starts a new activity to do that as it can not do on its own.
Everything is ok except the activity get closed before the dialog appears, so I get a window leaked exception but I can not see how I can make it works, waiting for the result of the dialog (uncomment the loop in the NumberDialog class) results in no exception but no dialog.

The sources are:

package com.frisco.hello;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.SQLException;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import com.frisco.hello.util.DataBaseHelper;

public class Caller extends BroadcastReceiver {

    private static final String TAG = "HelloWorld";

    @Override
    public void onReceive(Context context, Intent intent) {
        String intentAction = intent.getAction();
        String number = getResultData();

        if (intentAction.equals(Intent.ACTION_NEW_OUTGOING_CALL) && number != null)
        {
            Log.d(TAG, "Recibido evento por el numero" + number);
            DataBaseHelper myDbHelper = new DataBaseHelper(context);         
            try {            
                myDbHelper.createDataBase();             
            } catch (IOException ioe) {          
                throw new Error("Unable to create database");            
            }            
            try {            
                myDbHelper.openDataBase();           
            }catch(SQLException sqle){           
                throw sqle;          
            }
            String[] results = myDbHelper.getAlternateNumbers(number);
            if (results.length > 1) {

                intent = new Intent(Intent.ACTION_CALL,
                        Uri.fromParts("com.frisco.hello.number", Uri.decode(number),null));
                number = null;
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);  
            }
        }
    }   

}

Number dialog:

package com.frisco.hello;

import java.io.IOException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.database.SQLException;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;

import com.frisco.hello.util.DataBaseHelper;

public class NumberDialog extends Activity {
    private static final String TAG = "HelloWorld"; 
    private CharSequence[] alternates;
    private CharSequence selected = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);

        Uri uri = getIntent().getData();
        String target = uri.getSchemeSpecificPart();
        Log.d(TAG,"Decodificado el numero como "+target);
        DataBaseHelper myDbHelper = new DataBaseHelper(this);        
        try {            
            myDbHelper.createDataBase();             
        } catch (IOException ioe) {          
            throw new Error("Unable to create database");            
        }            
        try {            
            myDbHelper.openDataBase();           
        }catch(SQLException sqle){           
            throw sqle;          
        }  
        String[] results = myDbHelper.getAlternateNumbers(target);
        alternates = results;
        new AlertDialog.Builder( this)
            .setTitle( "Select number" )
            .setItems( results, new DialogSelectionClickHandler())
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        finish();
                    }
                })
            .setOnCancelListener(new OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    finish();
                }
            })          
            .show(); 
/*      while (selected == null) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                ;
            }
        }
        Log.i( TAG, "Seleccionado " + selected );
*/      
    }

    public class DialogSelectionClickHandler implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener
    {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Log.i( TAG, which+"_"+alternates[which] );
            selected = alternates[which];
        }

        @Override
        public void onDismiss(DialogInterface dialog) {
            Log.i( TAG, "Dismissed" );
            selected = alternates[0];
        }
    }    
}

LogCat

09-29 17:52:28.309: ERROR/WindowManager(4464): Activity com.frisco.hello.NumberDialog has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e48270 that was originally added here
09-29 17:52:28.309: ERROR/WindowManager(4464): android.view.WindowLeaked: Activity com.frisco.hello.NumberDialog has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@43e48270 that was originally added here
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.Dialog.show(Dialog.java:241)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at com.frisco.hello.NumberDialog.onCreate(NumberDialog.java:56)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.os.Looper.loop(Looper.java:123)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at java.lang.reflect.Method.invokeNative(Native Method)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at java.lang.reflect.Method.invoke(Method.java:521)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-29 17:52:28.309: ERROR/WindowManager(4464):     at dalvik.system.NativeStart.main(Native Method)
  • 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-17T15:01:12+00:00Added an answer on May 17, 2026 at 3:01 pm

    It seems that I can not activate other Activity while in the phone call process.
    But that was not what I was trying, stopping the current call showing a dialog and then starting a new one with different number.
    So the fix is as simple as changing on the Caller class:
    number = null;
    for
    setResultData(null);
    which indeed ends the calls and allow my new activity to show its dialog.

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

Sidebar

Related Questions

I'm writing an android app where you have a recursive function that takes a
I'm writing an Android app and I have a class that generates and maintains
I'm writing an Android app that is parsing RSS feeds from different sources. What
I am writing an Android app that will communicate with the PC. I tried
So I am writing an Android app and want to have a function that
Im writing an android app that connects to my own Jersey rest client. HTTP
I am currently writing an Android app that, among other things, uses text information
I'm writing an Android app that needs to access GMail, and I'd like to
So I'm writing an android app that needs to grab book price data from
I am writing and Android app that uses the camera. Once activity saves 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.