0

我通过一个整数值(引导)到下一类(活性)这样的改变第二时间: 在不同的活动..第一:int值不尽管onNewIntent()

   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()被调用(级别选择器)。它收到的意图,并采取正确的条款,我再次开始于Story001 ..这部分工作正确 但如果我在故事003a失败价值指南传递与故事001a意图完全一样..但这一次在尽管我使用onNewIntent()来打开相同的活动。

我需要更改哪些内容?有任何想法吗?

在此先感谢!

这里是manisfest:

<?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> 

+1

当用户“在某个时间点失败e故事“ - 你能告诉我们你用来决定哪些活动应该开放的代码吗? – ishmaelMakitla

+0

这两部分在同一活动中运行? –

+0

公共无效levelAuswahl()是决定哪些活动应该是开放的levelAuswahl = levelChooser英语 –

回答

0

而不是使用

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); 
} 
0

getIntent()返回IntentActivity启动时使用(即:导致onCreate()要调用的一个。如果您要返回到GameOver和的现有实例没有被调用,那么你会得到新的IntentonNewIntent()交付。传递给onNewIntent()Intent应该包含正确的额外值。

如果这不是你的情况,请给出你的情况的更多细节。

+0

我才明白你正确的,问题是,如果我到GAMEOVER activty来第二次活动不创造第二次,因此VAR导向不会改变?如果是的话,你可以更准确地说_我必须使用'onNewIntent'? –

+0

你知道是否第二次调用GameOver.onCreate()吗?你可以添加日志记录来验证这一点?这将解释你所看到的行为。如果是这样,问题是:你期望'onCreate()'不被第二次调用?请按照我的要求发布清单。 –

+0

我用的断点和我停在的onCreate()两次.. 如何做我需要更改线路,其中我收到意图是什么?那么,而不是:指南= getIntent()。getIntExtra(“指南”,0); ..? –