统一集成与Eclipse:后退按钮点击 [英] Integrating Unity with Eclipse: Back Button Click
问题描述
我使用的是按钮,然后我启动统一活动主要活动,但我需要完成它,并返回到previous活动,而是整个应用程序被关闭。
I have a main activity using a button then i launch the unity activity, but i need to finish it and go back to the previous activity, but instead the whole app is closed.
我能做些什么? 谢谢!
What can I do? Thank you!
编辑:
我用的是AR玩家从高通公司扩增实境(统一扩展) 我只有一个,我开始从高通公司扩增实境的AR玩家主要活动。
I use the AR player from Qualcomm Augmented Reality (Unity Extension) I have only one main activity which I start the AR player from Qualcomm Augmented Reality.
主要活动的
public class Main extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onBtnStartClick(final View v) {
Intent i= new Intent(this,ArPart.class);
startActivity(i);
}
}
AR玩家活动的
public class ArPart extends QCARPlayerActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
finish();
}
return super.onKeyDown(keyCode, event);
}
}
推荐答案
我发现它最容易使用的覆盖 onBack pressed()
,但要做到这一点,你还必须做出改变在统一的项目:
I found it easiest to use the overridden onBackPressed()
but to do that you also have to make a change in your Unity project:
void Update ()
{
if (Input.GetKeyUp (KeyCode.Escape)) {
AndroidJavaClass jc = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject> ("currentActivity");
jo.Call ("onBackPressed");
}
}
然后,在你的活动类:
Then, in your activity class:
@Override
public void onBackPressed() {
// Handle the activity however you want,
// what you do here will be executed when the back button is pressed
}
此外,请记住这个工作不出所料,UnityPlayer对象的不能暂停 - 你应该暂停它,你已经处理后退按钮preSS事件之后
Also, remember that for this to work as expected, the UnityPlayer object cannot be paused - you should pause it after you've handled the back button press event.
幸得@Frank阮从这个主题:<一href="http://stackoverflow.com/questions/21206615/cant-pass-back-event-from-unity-to-android-library-jar">Can't回传事件从统一到Android库JAR 。
Credit goes to @Frank Nguyen from this thread: Can't pass back event from Unity to android library jar.
这篇关于统一集成与Eclipse:后退按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!