When I return back to 1st Activity the onCreate() function of 2nd Activity is not called in 2nd time

StackOverflow https://stackoverflow.com/questions/23603227

  •  20-07-2023
  •  | 
  •  

Question

I have Two Activities Dial pad and phone. In dial Pad activity there is a edit box and buttons to dial the number and In the phone activity there are 5 lines to call.when u select the line 1 the dial activity is open and so on.The problem im facing is First time when i select any line from phone activity the onCreate function of dial activity is cal and when I return back to the phone activity and select other line the onCreate() function of the dial activity is not called. The onStart() function of the dial activity is cal and i want to cal the onCreate() function.plz help me to solve this problem.

public class DialPad extends Activity 
{
    private TextView m_objStatus;
    private Button m_objBtnDial; 




    int m_nLineNo = -1;
    boolean m_objContactFlag;

    public static Phone m_objPhone;
    private static String[] m_objPhoneNum = new String[VaxSIPUserAgent.TOTAL_LINE_COUNT];

    public void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        Phone.m_objDialPad = this;

        Intent intent = getIntent();

        int nIntentExtraLineNo = intent.getIntExtra("LineNo", 1);
        m_nLineNo = nIntentExtraLineNo; 



        final int [] aLineArray =  new int[VaxSIPUserAgent.TOTAL_LINE_COUNT - 1];

        int nIndex = 0;

        for (int nLineNo = 0; nLineNo < VaxSIPUserAgent.TOTAL_LINE_COUNT; nLineNo++)
        {
            if(m_nLineNo ==  nLineNo)
                continue;

            aLineArray[nIndex] =  nLineNo + 1;
            nIndex++;

        }

        String sLineStatus = VaxStatus.m_objVaxStatus.GetLineStatus(m_nLineNo);
        OnStatusPhone(sLineStatus);


             String sPhoneNo = intent.getStringExtra("PhoneNo");

        if(sPhoneNo != null)
        {
            m_objPhoneNum[nIntentExtraLineNo] = sPhoneNo;
        }

        m_objEditDialscreen.setText(m_objPhoneNum[nIntentExtraLineNo]);
    }




    @Override
    protected void onStart() 
    {



        UpdateDialBtn();


        if(m_objContactFlag == false)
            m_objEditDialscreen.setText(m_objPhoneNum[m_nLineNo]);

        IncommingCallSlider.m_objCallSlider.SetActiveActivity(this, R.id.dialpad);
        IncommingCallRing.m_objIncommingCallRing.SetActiveActivity(this);

        DialCallTone.m_objDialCallTone.SetActiveActivity(this);

        super.onStart();
    }



    @Override
    protected void onStop() 
    {
        m_objPhoneNum[m_nLineNo] = m_objEditDialscreen.getText().toString();
        super.onStop();
    }


 }
Was it helpful?

Solution 2

Add the following method to your Dial activity:

@Override
    protected void onPause() 
    {
       finish();   
    }

OTHER TIPS

onCreate is called when the Activity is created.

Once you come back, onResume will be called.

If you have some code that should run both on onCreate and onResume, you should put it in onResume, while onResume is always called, whether you are creating a new activity or you are coming back to an already running activity.

See the activity life-cycle in this diagram:

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top