尽管有 onNewIntent(),但通过 intents 传递的 int 值不会第二次改变
int value passed with intents doesn't change second time despite onNewIntent()
我将整数值(指南)传递给下一个 class(activity),如下所示:
在不同的活动中.. 第一:
public void onClick(View v) {
Intent intent002a = new Intent(getApplicationContext(), GameOver002a.class);
intent002a.putExtra("guide", 11001001);
startActivity(intent002a);
}
秒:
public void onClick(View v) {
Intent intent003a = new Intent(getApplicationContext(), GameOver002a.class);
intent003a.putExtra("guide", 11002001);
startActivity(intent003a);
}
等等..
然后我收到了意图:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_game_over002a);
onNewIntent(getIntent());
}
@Override
protected void onStart() {
super.onStart();
UnityAds.changeActivity(this);
UnityAds.init( this, "*******", this);
UnityAds.setDebugMode(true);
UnityAds.setTestMode(true);
TextView neinTextView = (TextView) findViewById(R.id.nein_textview002a);
if (neinTextView != null) {
neinTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Startbildschirm.class);
startActivity(intent);
}
});
}
TextView jatextview = (TextView) findViewById(R.id.ja_textview002a);
if (jatextview != null) {
jatextview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(GameOver002a.this)
.setMessage("Watch a short ad to continue at the last checkpoint?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
if (UnityAds.setZone("rewardedVideo") && UnityAds.canShow()) {
UnityAds.show();
}}
}).create().show();
}
});
}
}
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setMessage(R.string.zurück_zum_menü_frage)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent(getApplicationContext(), Startbildschirm.class);
startActivity(intent);
}
}).create().show();
}
@Override
public void onHide() {
}
@Override
public void onShow() {
}
@Override
public void onVideoStarted() {
}
@Override
public void onVideoCompleted(String s, boolean b) {
levelAuswahl();
}
@Override
public void onFetchCompleted() {
}
@Override
public void onFetchFailed() {
TextView jatextview = (TextView) findViewById(R.id.ja_textview002a);
if (jatextview != null) {
jatextview.setText(R.string.videoladen_fail);
jatextview.setClickable(false);
}
}
@Override
public void onResume()
{
super.onResume();
UnityAds.changeActivity(this);
onNewIntent(getIntent());
}
public void levelAuswahl() {
int guide;
guide = getIntent().getIntExtra("guide",0);
if (guide == 11001001) {
Intent intent = new Intent(getApplicationContext(), Story001a.class);
startActivity(intent);
}else if (guide == 11002001) {
Intent intent = new Intent(getApplicationContext(), Story002b.class);
startActivity(intent);
}else if (guide == 11007001) {
Intent intent = new Intent(getApplicationContext(), Story004a.class);
startActivity(intent);
} else {
Intent intent = new Intent(getApplicationContext(), Startbildschirm.class);
startActivity(intent);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// getIntent() should always return the most recent
setIntent(intent);
}
}
选择正确的activity..故事的每个部分都有自己的ACTIVITY
以下场景:
我启动应用程序并在 Story002a activity 处失败 .. 然后我传递一个整数值(指南)并带有意图 .. 观看广告成功后,方法 levelAuswahl() 被调用(级别选择器)。它接收到意图并采用正确的 if 子句,然后我从 Story001 重新开始。这部分工作正确
但是.. 如果我在 Story003a 失败,价值指南将以与 Story002a 完全相同的意图传递..但是这次在同一个活动中打开,尽管我使用 onNewIntent()..
我需要改变什么?有什么想法吗?
提前致谢!
这是清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".Startbildschirm"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Tutorial"
android:screenOrientation="landscape"/>
<activity android:name=".Support"
android:screenOrientation="landscape"/>
<activity android:name=".GameOver"
android:screenOrientation="landscape"/>
<activity android:name=".Story001a"
android:screenOrientation="landscape"/>
<activity android:name=".Story002a"
android:screenOrientation="landscape"/>
<activity android:name=".Story002b"
android:screenOrientation="landscape"/>
<activity android:name=".Story003a"
android:screenOrientation="landscape"/>
<activity android:name=".Story003b"
android:screenOrientation="landscape"/>
</application>
getIntent()
returns Activity
开始的 Intent
(即:导致 onCreate()
被调用的那个。如果你是返回到 GameOver
的现有实例,并且 onCreate()
未被调用,那么您将在 onNewIntent()
中获得新的 Intent
。传递给 Intent
onNewIntent()
应该包含正确的额外值。
如果这不是您的情况,请详细说明您的情况。
而不是使用
android:launchMode="singleTask" //or singleTop
已使用
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
一切正常
像这样使用 onNewIntent() 来获得您的新意图
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// getIntent() should always return the most recent
setIntent(intent);
}
我将整数值(指南)传递给下一个 class(activity),如下所示: 在不同的活动中.. 第一:
public void onClick(View v) {
Intent intent002a = new Intent(getApplicationContext(), GameOver002a.class);
intent002a.putExtra("guide", 11001001);
startActivity(intent002a);
}
秒:
public void onClick(View v) {
Intent intent003a = new Intent(getApplicationContext(), GameOver002a.class);
intent003a.putExtra("guide", 11002001);
startActivity(intent003a);
}
等等..
然后我收到了意图:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_game_over002a);
onNewIntent(getIntent());
}
@Override
protected void onStart() {
super.onStart();
UnityAds.changeActivity(this);
UnityAds.init( this, "*******", this);
UnityAds.setDebugMode(true);
UnityAds.setTestMode(true);
TextView neinTextView = (TextView) findViewById(R.id.nein_textview002a);
if (neinTextView != null) {
neinTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Startbildschirm.class);
startActivity(intent);
}
});
}
TextView jatextview = (TextView) findViewById(R.id.ja_textview002a);
if (jatextview != null) {
jatextview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(GameOver002a.this)
.setMessage("Watch a short ad to continue at the last checkpoint?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
if (UnityAds.setZone("rewardedVideo") && UnityAds.canShow()) {
UnityAds.show();
}}
}).create().show();
}
});
}
}
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setMessage(R.string.zurück_zum_menü_frage)
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
Intent intent = new Intent(getApplicationContext(), Startbildschirm.class);
startActivity(intent);
}
}).create().show();
}
@Override
public void onHide() {
}
@Override
public void onShow() {
}
@Override
public void onVideoStarted() {
}
@Override
public void onVideoCompleted(String s, boolean b) {
levelAuswahl();
}
@Override
public void onFetchCompleted() {
}
@Override
public void onFetchFailed() {
TextView jatextview = (TextView) findViewById(R.id.ja_textview002a);
if (jatextview != null) {
jatextview.setText(R.string.videoladen_fail);
jatextview.setClickable(false);
}
}
@Override
public void onResume()
{
super.onResume();
UnityAds.changeActivity(this);
onNewIntent(getIntent());
}
public void levelAuswahl() {
int guide;
guide = getIntent().getIntExtra("guide",0);
if (guide == 11001001) {
Intent intent = new Intent(getApplicationContext(), Story001a.class);
startActivity(intent);
}else if (guide == 11002001) {
Intent intent = new Intent(getApplicationContext(), Story002b.class);
startActivity(intent);
}else if (guide == 11007001) {
Intent intent = new Intent(getApplicationContext(), Story004a.class);
startActivity(intent);
} else {
Intent intent = new Intent(getApplicationContext(), Startbildschirm.class);
startActivity(intent);
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// getIntent() should always return the most recent
setIntent(intent);
}
}
选择正确的activity..故事的每个部分都有自己的ACTIVITY
以下场景: 我启动应用程序并在 Story002a activity 处失败 .. 然后我传递一个整数值(指南)并带有意图 .. 观看广告成功后,方法 levelAuswahl() 被调用(级别选择器)。它接收到意图并采用正确的 if 子句,然后我从 Story001 重新开始。这部分工作正确 但是.. 如果我在 Story003a 失败,价值指南将以与 Story002a 完全相同的意图传递..但是这次在同一个活动中打开,尽管我使用 onNewIntent()..
我需要改变什么?有什么想法吗?
提前致谢!
这是清单:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.NoActionBar">
<activity android:name=".Startbildschirm"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Tutorial"
android:screenOrientation="landscape"/>
<activity android:name=".Support"
android:screenOrientation="landscape"/>
<activity android:name=".GameOver"
android:screenOrientation="landscape"/>
<activity android:name=".Story001a"
android:screenOrientation="landscape"/>
<activity android:name=".Story002a"
android:screenOrientation="landscape"/>
<activity android:name=".Story002b"
android:screenOrientation="landscape"/>
<activity android:name=".Story003a"
android:screenOrientation="landscape"/>
<activity android:name=".Story003b"
android:screenOrientation="landscape"/>
</application>
getIntent()
returns Activity
开始的 Intent
(即:导致 onCreate()
被调用的那个。如果你是返回到 GameOver
的现有实例,并且 onCreate()
未被调用,那么您将在 onNewIntent()
中获得新的 Intent
。传递给 Intent
onNewIntent()
应该包含正确的额外值。
如果这不是您的情况,请详细说明您的情况。
而不是使用
android:launchMode="singleTask" //or singleTop
已使用
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
一切正常
像这样使用 onNewIntent() 来获得您的新意图
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// getIntent() should always return the most recent
setIntent(intent);
}