[英]Close MainActivity(main) from another activity (ActivityPoliticas)
I'm looking for a solution to press the (non-personalized ads) button of the ActivityPolicies and close the MainActivity and then reopen the MainActivity with the correct ad.我正在寻找一种解决方案来按下 ActivityPolicies 的(非个性化广告)按钮并关闭 MainActivity,然后使用正确的广告重新打开 MainActivity。
MainActivity(principal)主要活动(主体)
public void politicas(View view) // button
{
Intent i = new Intent (this, ActivityPolicies.class);
i.putExtra("valor","politicas");
startActivity(i);
}
ActivityPolicies活动政策
public void NonPersonalizedAdvertising(View view) //button
{
SharedPreferences myPreferences = PreferenceManager.getDefaultSharedPreferences(MensajePoliticas.this);
SharedPreferences.Editor myEditor =myPreferences.edit();
myEditor.putString("POLITICAS","LEIDO_NOACEPTADO");
myEditor.commit();
//Missing some option to close the main activity
*
*
*
//Reopen the main activity
Intent entrar=new Intent(this,MainActivity.class);
startActivity(entrar);
finish(); // Close the current activity (ActivityPolicies)
}
The goal is to close the MainActivity to reload the correct personalized or non-personalized ad.目标是关闭 MainActivity 以重新加载正确的个性化或非个性化广告。 I already have the code but I am missing this option to reload the MainActivity.我已经有了代码,但我缺少重新加载 MainActivity 的选项。
Another question: Close the main activity to reload the ads, can I have problems with some Admob rule?另一个问题:关闭主要活动以重新加载广告,我会遇到一些 Admob 规则的问题吗?
Thank you very much非常感谢你
If your MainActivity is in backstack, you can call same activity like this:如果您的 MainActivity 在 backstack 中,您可以像这样调用相同的活动:
Intent entrar = new Intent(this,MainActivity.class);
entrar.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // this will open the same MainActivity instance and also give you a new intent.
startActivity(entrar);
Now in your MainActivity you can override onNewIntent现在在您的 MainActivity 中,您可以覆盖 onNewIntent
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// here you will get the new Intent. You can reload only the ads programmatically or just call `this.recreate();`
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.