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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:44:32+00:00 2026-05-26T20:44:32+00:00

I have been looking for that so much and I haven’t found the solution.

  • 0

I have been looking for that so much and I haven’t found the solution.

My applications calls a number all time, and when it receives an incoming call with an exactly number it stops (dies).
My idea is that:

  1. Activity launches Service that does the job of calling
  2. A BroadcastReceiver that is expecting for the incoming call

So, I want to use the BroadcastReceiver to kill the Activity, but I haven’t found any solution to this. To try another thing, I tried to send an Intent with Extras but the Extras have become null.

I’m open to use any other solution that solve it!

Thank-you very very much!

UPDATED CODE TO DO THE RECOMMENDATION OF Kurtis Nusbaum
I see that the problem is in the Service when it makes the call, so I put all my code

Here my code:

package com.comunicacio;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;

public class Comunicacio extends Activity {

    IntentFilter filter;

    private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i("BYE", "OOOOOOOOOOOOK");
            finish();
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        filter = new IntentFilter();
        filter.addAction("com.comunicacio.FINALITZAR");

        startService(new Intent(this, Servicio.class));
    }

    @Override
    protected void onResume() {
        super.onResume();
        registerReceiver(receiver, filter);
    }

    @Override
    protected void onPause() {
        super.onPause();
        unregisterReceiver(receiver);
    }

}

The BroadcastReceiver:
package com.comunicacio;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

public class DetectarCridada extends BroadcastReceiver {
    public static final String CUSTOM_INTENT = "com.comunicacio.FINALITZAR";

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();

        if (bundle == null)
            return;

        String state = bundle.getString(TelephonyManager.EXTRA_STATE);

        if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) {
            String phonenumber = bundle
                    .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

            Log.i("BYE", "UUUUUUUUUUUUUUUUL");

            // if (es_acceptat(phonenumber)) {
            Intent i = new Intent();
            i.setAction(CUSTOM_INTENT);
            context.sendBroadcast(i);
            // }
        }
    }

    private boolean es_acceptat(String telefono) {
        if (telefono.equals("123"))
            return true;
        return false;
    }
}

And Manifest:

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name="Comunicacio" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name=".DetectarCridada" >
            <intent-filter >
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>
        <service
            android:enabled="true"
            android:name=".Servicio" />

        <activity android:name=".Call" />
    </application>

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
</manifest>

The Service Sercivio.java:
package com.comunicacio;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class Servicio extends Service {
    private static final String TAG = "MyService";
    boolean hem_cridat = false;
    int telefono = 123;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
        Log.d(TAG, "onCreate");
        EndCallListener callListener = new EndCallListener();
        TelephonyManager mTM = (TelephonyManager) this
                .getSystemService(Context.TELEPHONY_SERVICE);
        mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
    }

    @Override
    public void onDestroy() {
        Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onStart(Intent intent, int startid) {
        Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
        call();
    }

    private class EndCallListener extends PhoneStateListener {
        private static final String LOG_TAG = "Comunicacio:";

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
            case TelephonyManager.CALL_STATE_RINGING:
                Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                Log.i(LOG_TAG, "OFFHOOK");
                hem_cridat = true;
                break;
            case TelephonyManager.CALL_STATE_IDLE:
                Log.i(LOG_TAG, "IDLE");
                if (hem_cridat) {
                    hem_cridat = false;
                    try {
                        Log.i(LOG_TAG, "Cridant!");
                        call();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                break;
            }
        }
    }

    private void call() {
    /* THE PROBLEM IS THERE !!! If I don't do that, it works! */
    /*  Intent i = new Intent(getBaseContext(), Call.class);
        i.putExtra("NUMERO", telefono);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getApplication().startActivity(i);
        ++telefono; */
    }
}

And finally Call.java:
package com.comunicacio;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class Call extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle b = getIntent().getExtras();
        Intent i = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
                + b.getInt("NUMERO")));
        startActivity(i);
    }
}

Thank-you very very much!

  • 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-26T20:44:32+00:00Added an answer on May 26, 2026 at 8:44 pm

    The problem was on:

    @Override
    protected void onPause() {
        super.onPause();
        unregisterReceiver(receiver);
    }
    

    It stopped the Receiver, so I have changed it to:

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(receiver);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have been looking all over and I haven't quite found what I
Have been looking at the MVC storefront and see that IQueryable is returned from
I've been looking around for quite a while and feel that I have a
I have been looking around for a regex expression that will spit out just
I have been looking into recursion and TCO. It seems that TCO can make
I've been writing some jQuery functions that have JavaScript variables and looping, etc inside
I have been looking into IKVMing Apache's FOP project to use with our .NET
We have been looking at g++ versions 3.2.3 and 4.2.4. With 4.2.4, the performance
I have been looking at metrics for coupling and also look at DSM .
I have been looking for documentation related to interacting with MSPaint from the command

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.