我将一个整数值(指南)传递给下一个类(活动),如下所示:在不同的活动中......首先:
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);
}
}
选择正确的活动。故事的每个部分都有自己的活动
以下场景:我启动应用程序并在 Story002a 活动中失败..然后我传递一个整数值(指南),意图..在成功观看广告后,调用方法 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>