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

问题描述 投票:-1回答:2

我的应用程序有问题,我不知道该怎么做才能修复它。我是Android新手,不懂java。

该应用程序由包含列表的多个页面组成,所有页面都包含一个在这些页面之间导航的微调器您在微调框中选择项目,应用程序将打开该页面。除了在页面之间跳转之外,在微调器中还有一个“退出应用程序”的选项。

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

有没有办法,当我通过按设备上的主页键退出应用程序,或者从微调器点击退出应用程序,然后重新启动应用程序,它是否在仪表板上打开?

有人可以帮忙吗?

谢谢。

字符串代码......

<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)是使用微调项目选项打开的页面。

案例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();
    }
}
android exit restart
2个回答
0
投票

put this snippet in all of your classes

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

这将难以解决问题。


1
投票

答案:

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);
© www.soinside.com 2019 - 2024. All rights reserved.