退出应用程序后如何让我的应用程序启动到仪表板?

How do I get my app to launch to the dashboard after exiting app?

我的一个应用程序有问题,我不知道如何解决它。我是 Android 的新手,不了解 java。

该应用程序由包含列表的多个页面组成,所有页面都带有一个微调器以在这些页面之间导航。您 select 在微调器中的项目中,应用程序会打开该页面。除了在页面之间跳转之外,在微调器中还有一个 'Exit App'.

的选项

页面跳转没问题。我遇到的问题是 'Exit App' 代码。当我通过按设备上的主页键或点击退出应用程序(从微调器)退出应用程序然后重新启动应用程序时,它不会在仪表板上打开,而是在我上次查看的页面上打开。为了解决这个问题,我需要长按设备的home键,然后从最近使用的列表中滑动应用。

有没有一种方法可以让当我通过按设备上的主页键退出应用程序,或者通过点击微调器中的退出应用程序然后重新启动应用程序时,它确实会在仪表板上打开?

有人能帮忙吗?

谢谢。

字符串代码...

<string-array name="TheList">
   <item>Tap Here For List…</item>
   <item>Cheese</item>
   <item>Planets</item>
   <item>Cars</item>
   <item><b>Back To Dashboard…</b></item>
   <item><b>EXIT APP</item>
</string-array>

下面代码中的案例编号 (1-4) 是使用微调项打开的页面 selection。

案例5退出应用。我假设代码中存在错误,阻止应用程序在仪表板上重新启动。

java代码...

package com.example.acer.MyKitList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;

public class Carrying extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.page1);


   // Spinner element & Spinner click listener
   Spinner Spinner = (Spinner) findViewById(R.id.Spinner1);

   Spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {


       @Override
       public void onItemSelected(AdapterView<?> arg0, View view, int position, long row_id) {

      switch (position) {
          case 1:
         Intent a = new Intent(Dashboard.this, Cheese.class);
         startActivity(a);
         finish();
         break;
          case 2:
         Intent b = new Intent(Dashboard.this, Planets.class);
         startActivity(b);
         finish();
         break;
          case 3:
         Intent c = new Intent(Dashboard.this, Cars.class);
         startActivity(c);
         finish();
         break;
          case 4:
         Intent d = new Intent(Dashboard.this, Dashboard.class);
         startActivity(d);
         finish();
         break;

          case 5:
         Intent intent = new Intent(Intent.ACTION_MAIN);
         intent.addCategory(Intent.CATEGORY_HOME);
         intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
         startActivity(intent);
         System.exit(0);
         finish();

      }
       }

       @Override
       public void onNothingSelected(AdapterView<?> arg0) {
       }
   });
    }

    @Override
    public void onBackPressed() {
   finish();
    }
}

将此片段放入您的所有 类

@Override
protected void onResume() {
    super.onResume();
   //Start Dashboard Activity here
     Intent a = new Intent(context, Dashboard.class);
     startActivity(a);
     finish();
     }
}

这将硬性解决问题。

The answer:

case 5:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
System.exit(0);