Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Destroy an Intent?

Tags:

android

When I create a Intent:

Intent in = new Intent(this, myclass.class);
this.startActivity(in);

I create a new Intent but the last Intent is not destroy
It's still in memory
How can I kill this last destroy?

So I want to create two Intents in two different classes: in the first class I write this:

Intent in1 = new Intent(this, myclass2.class);
this.startActivity(in);

and in second class I write this:

Intent in2 = new Intent(this, myclass1.class);
this.startActivity(in2);

but when I Click in1 will create and the in2 will destroy, and when i Click on in2 the in2 will create and in1 will destroy.

a want to clean my phone memory.

like image 336
shelltrayWnd Avatar asked Aug 14 '26 09:08

shelltrayWnd


2 Answers

You can prevent the user from going on to the previous Activity by overriding the back key functionality like this:

public void onBackPressed() {
       //doing nothing on pressing Back key
       return;
    }

Though this approach is not encouraged.And as everybody knows, the Activity will be automatically killed when certain aspects come up like memory requirement. You cannot destroy one Activity at your free will.

Though for specific cases like a welcome splash screen maybe, you can do one of the following two things:

1) call finish() method on your current Activity as you move onto your new Activity(generally done when using Thread).

2) use the following in your manifest:

<activity android:name=".WelcomeScreen" android:noHistory="true" ... />

This will tell the device to not keep this Activity on the Activity stack.

like image 81
Kazekage Gaara Avatar answered Aug 17 '26 00:08

Kazekage Gaara


Activities remain in memory until Android decides it should be removed. Don't worry about it. It'll get destroyed when more memory is needed. It's effectively "unused" memory until your top activity uses it.

like image 23
DeeV Avatar answered Aug 17 '26 00:08

DeeV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!