3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UnityのAndroidでバックキーを押した挙動をホームボタンと一緒にする

Posted at

使用環境

Unity2019.2.11

結論

ゲーム内にあるオブジェクトどれかのUpdate内を以下のようにすると、
バックキーを押した際にタスクキルではなくアプリのタスクをバックグラウンドに持っていける

   void Update()
   {
      if (Input.GetKeyDown(KeyCode.Escape))
      {
#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").
                GetStatic<AndroidJavaObject>("currentActivity");
            activity.Call<bool>("moveTaskToBack" , true);
#endif
      }
   }
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?