In onAdDismissedFullScreenContent of Interstitial Ad start new Activity using startActiviy(Intent(...)) in normal case ad show and close the inter ad the new Activity start normally.
The issue is when Inter Ad show then I press home button and open app again from recents then I press on inter ad close the Ad close but the new Activity start after few seconds why.
here is onAdDismissedFullScreenContent code
override fun onAdDismissedFullScreenContent() {
startActivity(new Intent(this, NewActivity.class));
finish()
}
Related
I have a "Close" button which closes the application.
I have tried 2 methods but they both are very slow.
Finishing the activity:
activity.finish()
Sending Home Page intent (from here)
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
How can I close the activity or send it to the background faster?
Why clicking on the "home" button is much faster than sending ACTION_MAIN intent?
Pressing the HOME Button will call onPause() on the current Activity. Thus it's not closing the app in total but pause it.
Ergo: It is of course much faster even in starting because it keeps the memory.
Now you know how to pause the app instead of closing if you want to have a fast approach.
If you want to close the whole app I would suggest to use finishAndRemoveTask();
Finishes all activities in this task and removes it from the recent
tasks list.
Note: BACK Button will call onDestroy() if you want to have another way. Try out what fits best for your usage.
CODE EXAMPLE
Close app like HOME Button programmatically without a transparent View using a Button:
Button close = findViewById(R.id.myCloseButton);
close.setOnClickListener(view -> {
finishAffinity();
});
im trying to make a custom ad for a client, and he needs that when the user loads the app it shows the ad, he needs control of the img of the ad so i load it from an external url.
The app starts with a SplashActivity that loads everytime the app starts, and after that i start the activity CustomAdActivity that has a Relative Layout with the ad. The thing is that when they click i send them to the ad this way:
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse("AD_URL"));
startActivity(viewIntent);
And it works fine, but then i need to send the user to the MainActivity, and if just put below
Intent mainIntent = new Intent(CustomAdActivity.this, MainActivity.class);
startActivity(mainIntent);
the app just straight sends the user to the main activity without opening the url,
i tried to put it in onPause, onStart and in onDestroy when i call finish(); after the url intent but it just doesn't work (with the last one just killing the app) i would love if someone helps me
I'm new in android development, and there is something about the life cycle activity that I don't understand, especially with the following example of application that i'm working on.
In my app, I have a Login activity and a Main activity.
In my Login activity, with successful attempt, there is a Intent that start the main activity, and finish() the login activity.
==> There, my login activity is destroyed, so this should not show up again.
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("authentResult", tokenDto);
startActivity(intent);
finish(); //destroy activity to not open it with back button`
In my Main activity, I have a disconnect button that create an Intent that start a (new ?) login activity.
==> Until there, everything's normal, and the login activity is displyed.
Intent loginActivity = new Intent(this, LoginActivity.class);
startActivity(loginActivity);
In the login activity, using the Back button should close the app.
To do that, I send an intent with special flag to the main activity to finish it (So the back button will not wake up the main activity), and then I finish the login activity. The onDestroy method is called and I see the login window close itself.
==> From here I expect the app to be closed. But a "new" login activity shows up, and i suspect that it would be the activity of the first point, so I'm a little lost there...
public void onBackPressed() {
Log.d(TAG, "BACK PRESSED - loginActivity");
//Finish MainActivity
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EXIT", true);
startActivity(intent);
finish(); // finish login activity
}
In the onCreate in the mainActivity, I begin with this :
if (getIntent().getBooleanExtra("EXIT", false)) {
finish();
}
Do anyone could explain to me what I'm missing, or show me a better way to close the app directly ?
Don't hesitate to telle me if something's not clear.
If you declare the Login activity as main activity in the Manifest, if you don't destroy it when you launch the second activity then i think the back button will do all you expect without any additional code, and if you press back key on the login activity it will go to phone home screen
On Android applications is the system that decides when to close/kill application.
We have created a phonegap application for android with phonegap version-1.3.
When I am on any page of the application, and start using the device BACK button, the Android SPLASH screen appears/pops sometimes, and then the previously accessed page is shown.
function onBackKeyPress()
Sometimes when i click on some links which open the browser, and after i click on back button, its Showing Splash screen and relaunch the application.
Is there any other function we can use for back button?
From the activity before splash screen from which you wish to exit application override onBackpress.
#Override
public void onBackPressed() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
I have 3 activities. start / game / finish, I want to go start to game, game to finish, finish to start. but when I use Intent one to another when I finish() "finish" Its come back to game. It should come back to start. so It needs a design kind of all Intents under start activity.
so I tried this one and expected when I finish() "finish" application will be destroy but It didnt work
Intent intent = new Intent(getApplicationContext(),FinishScreen.class);
startActivity(intent);
Q: so how can I start finish activity Intent under start activity but from game activity
When you call startActivity(...) in "game" Activity to start the "finish" Activity, immediately call finish() so "game" terminates. If you do that then BACK in the "finish" Activity will return to "start" because "game" self-terminated.
Intent intent = new Intent(getApplicationContext(),FinishScreen.class);
startActivity(intent);
finish();
The finish() method should work, try with: System.exit(0);