0

I have updated the latest Android Studio and created a new Blank Project. I added the following code to the MainActivity.java file, but onDestroy() is never called. Is there any way to get destroy event?

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.edevshop.destroy">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

</manifest>
CameraDev
  • 33
  • 4

1 Answers1

0

just check it out and modify your onDestroy() method as below:

@Override
protected void onDestroy() {
    Log.d("TAG", "Yay.. onDestroy called!");
    super.onDestroy();
}

Now... Run App > Open LOGCAT > close App (By pressing BACK button) You'll see a LOG.

Meet Vora
  • 2,783
  • 1
  • 16
  • 33