(Yes, I've already looked at existing questions related to this problem.)
I am calling finish()
from my Activity's Up button listener. But although onDestroy()
does get around to being called, first onPause()
is called and then, surprisingly, onCreate()
, which is causing real problems. Why is a new ScanningActivity
being launched by a call to the finish()
method of ScanningActivity?
I am logging invocations of all the life cycle functions and the order is this:
inside onClick() Listener for up button.
Inside onPause()
Inside onCreate() // this is what's hosing everything
Inside onStart()
Inside onResume()
Inside onWindowFocusChanged()
Inside onStop()
Inside onDestroy()
Why am I getting this sequence of events following a call to finish()
? Here's the ScanningActivity
code that calls finish()
, notice, in an onclick
listener (which is assigned within the onCreate()
method):
@Override
public void onCreate(Bundle savedInstanceState)
{
. . .
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Log.i("ScanningActivity", "inside onClick() -- Listener for up button being executed.");
android.widget.LinearLayout layt = (android.widget.LinearLayout) vCustView;
View vTemp = layt.findViewById(R.id.scanning_up);
if (null != vTemp)
{
Button btnUp = (Button) vTemp;
if (!btnUp.getText().equals("End"))
{
setResult(RESULT_CANCELED);
finish();
return;
}
}
}
. . .
}
As per Karakuri's request here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.calypso.myandroid">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
//
<uses-permission android:name="android.permission.SET_DEBUG_APP" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="@drawable/ail_logo"
android:label="@string/app_name"
android:theme="@style/AssistTheme">
<activity
android:name=".HomeScreenActivity"
android:label="@string/title_activity_home_screen"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".GradeActivity"
android:label="@string/title_activity_grade_assessment"
android:screenOrientation="portrait"
android:parentActivityName=".HomeScreenActivity"
android:noHistory="true"
/>
<activity
android:name=".ScanningActivity"
android:label="@string/title_activity_scanning"
android:screenOrientation="portrait"
android:parentActivityName=".GradeActivity"
/>
</application>
</manifest>
... and here is the calling code, which initially launches ScanningActivity
from inside the GradeActivity
:
if (bFinishedSuccessfully)
{
try
{
Log.i("GradeActivity", "SOMEHOW THIS IS AGAIN STARTING THE ScanningActivity!!!");
Intent intent = new Intent(this, ScanningActivity.class);
intent.putExtra("SessionInfo", m_hmActivate);
startActivity(intent);
}
catch (Exception ex)
{
Log.i("GradeActivity", "ex: " + ex.getMessage());
}
}
UPDATE: I modified the manifest a bit and the calling code, slightly, in an attempt to fix this, but to no avail. The behavior is still exactly as described originally. I've updated the question with the mods.
Activity
is logging each method? – CyprosetResult()
, you must start the activity withstartActivityForResult()
, notstartActivity()
. – HustedScanningActivity
? – BalesHistory
, and you will get back the older code which produced this error. – Bandeen