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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:09:46+00:00 2026-06-15T09:09:46+00:00

I have an activity named MainActivity. In which I have started another activity (ContentDetails)

  • 0

I have an activity named MainActivity.
In which I have started another activity (ContentDetails)

    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {

    Uri contactUri = ContentUris.withAppendedId(People.CONTENT_URI, id);
    Intent intent = new Intent(this, ContactDetails.class);
    intent.setData(contactUri);
    startActivity(intent);

}

And in ContactDetails.java I have written code to make a phone call.
but when I end call. It finishes all application instead of redirecting to base activity

following is the code of ContactDetails.java

    public class ContactDetails extends Activity{

    TextView nameField = null;
    TextView phoneField = null;
    TextView idField = null;

    final Context context = this;
    private Button button;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.details);

        idField = (TextView) findViewById(R.id.contact_id);
        nameField = (TextView) findViewById(R.id.contact_name);
        phoneField = (TextView) findViewById(R.id.contact_phone);

        button = (Button) findViewById(R.id.call_button);

        // add PhoneStateListener
        PhoneCallListener phoneListener = new PhoneCallListener();

        TelephonyManager telephonyManager;

        telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);

        // add button listener
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:03577899456"));
                startActivity(callIntent);

            }

        });


    }

    @Override
    protected void onStart() {

        super.onStart();

        Cursor cursor = managedQuery(getIntent().getData(), null, null, null, null);
        cursor.moveToFirst();

        //idField.setText(cursor.getString(cursor.getColumnIndex(People._ID)));
        nameField.setText(cursor.getString(cursor.getColumnIndex(People.DISPLAY_NAME)));
        phoneField.setText(cursor.getString(cursor.getColumnIndex(People.NAME)));

    }
    private class PhoneCallListener extends PhoneStateListener {

        private boolean isPhoneCalling = false;

        String LOG_TAG = "LOGGING 123";

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            if (TelephonyManager.CALL_STATE_RINGING == state) {
                // phone ringing
                Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
            }

            if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
                // active
                Log.i(LOG_TAG, "OFFHOOK");

                isPhoneCalling = true;
            }

            if (TelephonyManager.CALL_STATE_IDLE == state) {
                // run when class initial and phone call ended, need detect flag
                // from CALL_STATE_OFFHOOK
                Log.i(LOG_TAG, "IDLE");

                if (isPhoneCalling) {

                    Log.i(LOG_TAG, "restart app");

                    // restart app
                    try{
                    //  Intent intentAndroid = new Intent().setClass(this, ContactList.class);
                    Intent i = getBaseContext().getPackageManager()
                            .getLaunchIntentForPackage(getBaseContext().getPackageName());

                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                    }catch (Exception e) {
                        // TODO: handle exception
                    }

                    isPhoneCalling = false;
                }

            }
        }
    }

}
  • 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-06-15T09:09:47+00:00Added an answer on June 15, 2026 at 9:09 am

    Actually, I think you have to use

    startActivityForResult(callIntent, <RESULT_OK>);
    

    instead of

    startActivity(callIntent);
    

    And override onActivityResult() in your ContactDetails Activity.

    Try this and let me know what happen..

    Also from your code I suggest you to don’t use of Flag i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); As its clear the current Activities state Task.

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

Sidebar

Related Questions

i have a main Activity called Main which has onActivityResult Method. protected void onActivityResult(int
I have main activity which contains few radio buttons. Their is one button named
I have a ContentProvider named GeneralDataProvider . Which calls @Override public boolean onCreate() {
I have an broadcast-receiver that looks like the following within an activity named childActivity
I am having trouble with my activity management. So I have activity A which
I have an activity who's orientation is locked to portrait: <activity android:name=MainActivity android:label=@string/app_name android:screenOrientation=portrait
I have an Activity which has an 'OK' button. And I have an 'Edit'
This is a very basic doubt. I have a MainActivity, and I created another
In my manifest file, I have an activity declaration which looks something like this:
I have a main Activity and a Dialog through which I would like to

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.