简体   繁体   English

我的应用程序在最初启动到设备时会加载,但是退出应用程序并返回后,它甚至不会尝试启动

[英]My app loads when initially launched to the device, but after I exit the app, and go back in, it won't even try to launch

Ok so I am really new to Android, and to get going with things, I paid a developer to build me a simple app, and now I'm trying to wade through it to make sense of it. 好的,所以我真的是Android的新手,为了开始工作,我付了一个开发人员来为我构建一个简单的应用程序,现在我正尝试通过它来理解它。

The problem I am trying to solve is the initial launch screen the app goes to. 我要解决的问题是应用程序转到的初始启动屏幕。 I got this to change by going into the Android manifest file and changing this value: 通过进入Android清单文件并更改此值,我对此进行了更改:

 <activity android:label="@string/app_name" android:name="Home">

to this value: 达到这个值:

 <activity android:label="@string/app_name" android:name="Languages">

And when I deploy the app to my device, it loads the Languages class just fine! 当我将应用程序部署到设备上时,它会很好地加载Languages类! The problem is that when I leave the app and then try and go back in, it doesn't even try to launch the app, it just goes back to the home screen. 问题是,当我离开应用程序然后尝试重新进入时,它甚至没有尝试启动该应用程序,而是返回主屏幕。

There isn't anything that tells me what is going on, and attaching the debugger for after the app is initially closed won't work either. 没有任何信息可以告诉我发生了什么,并且在应用程序最初关闭后附加调试器也无法正常工作。

Does anybody have any ideas as to what might be going on? 是否有人对可能发生的事情有任何想法?

Here is the code from the Android Manifest file:` 这是来自Android Manifest文件的代码:

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:label="@string/app_name" android:name="Language">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" />

        </intent-filter>
    </activity>
    <activity android:name="About"></activity>
    <activity android:theme="@android:style/Theme.Light" android:name="Language"></activity>
    <activity android:name="Volume" android:theme="@android:style/Theme.Light"></activity>
    <activity android:name="Book" android:theme="@android:style/Theme.Light"></activity>
    <activity android:name="Chapter" android:theme="@android:style/Theme.Light"></activity>
    <activity android:name="Verse" android:theme="@android:style/Theme.NoTitleBar"></activity>
    <activity android:name="Settings"></activity>

</application>

` `

Then here is the code for the Home class which originally launched first:`package com.elan.reader; 这是最初启动的Home类的代码:package com.elan.reader;

   import android.app.Activity;
   import android.content.Intent;
   import android.os.Bundle;
   import android.os.Looper;
   import android.view.View;
   import android.widget.Button;
   import android.widget.ProgressBar;
   import android.widget.TextView;

   import com.elan.reader.util.DatabaseHelper;
   import com.elan.reader.util.DatabaseHelper_Spa;

    public class Home extends Activity implements View.OnClickListener{
/** Called when the activity is first created. */
Button aboutBtn,readBtn;
Home me;
DatabaseHelper myDatabaseAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    me=this;

    aboutBtn = (Button) findViewById(R.id.about);
    aboutBtn.setFocusable(true);
    aboutBtn.setOnClickListener(this);

    readBtn = (Button) findViewById(R.id.read);
    readBtn.setFocusable(true);
    readBtn.setOnClickListener(this);
    myDatabaseAdapter = DatabaseHelper.getInstance(me);
    if(!myDatabaseAdapter.databaseReady()){
        try{
            myDatabaseAdapter.copyDatabase2();
            DatabaseHelper_Spa myDatabaseAdapter_spa = DatabaseHelper_Spa.getInstance(me);
            myDatabaseAdapter_spa.copyDatabaseSpanish2();

        }catch(Exception e){
            e.printStackTrace();
        }
        myDatabaseAdapter.databaseReady();
    }else{
        //myDatabaseAdapter.close();

        if(myDatabaseAdapter.getSaveVerse()[0]!=null||!myDatabaseAdapter.getSaveVerse()[0].equals("")){
            String data[]=myDatabaseAdapter.getSaveVerse();
            Intent intent=new Intent(Home.this,  Verse.class);
            intent.putExtra("language",data[0]);
            intent.putExtra("volume_id",data[1]);
            intent.putExtra("chapter",data[2]);
            intent.putExtra("book",data[3]);
            intent.putExtra("book_id",data[4]);
            intent.putExtra("multiple_languages",false);
            startActivity(intent);

        }
    }
}
@Override
public void onClick (View view){
    if(view==aboutBtn){
        startActivity(new Intent(Home.this,  About.class));
    }else if(view==readBtn){
        ProgressBar seek = (ProgressBar) findViewById(R.id.seek);
        seek.setVisibility(View.VISIBLE);
        TextView msg = (TextView) findViewById(R.id.loading);
        msg.setVisibility(View.VISIBLE);
        new Thread(){
            public void run(){
                Looper.prepare();

                    if(myDatabaseAdapter.getSaveVerse()[0]==null||myDatabaseAdapter.getSaveVerse()[0].equals("")){
                        startActivity(new Intent(Home.this,  Language.class));
                    }else{
                        String data[]=myDatabaseAdapter.getSaveVerse();
                        Intent intent=new Intent(Home.this,  Verse.class);
                        intent.putExtra("language",data[0]);
                        intent.putExtra("volume_id",data[1]);
                        intent.putExtra("chapter",data[2]);
                        intent.putExtra("book",data[3]);
                        intent.putExtra("book_id",data[4]);
                        intent.putExtra("multiple_languages",false);
                        startActivity(intent);

                    }

                Looper.loop();
            }
        }.start();

    }
}

}` }`

And then here is the code for the new class I need to launch first:`package com.elan.reader; 这是我需要首先启动的新类的代码:package com.elan.reader;

  import java.util.ArrayList;

  import com.elan.reader.util.DatabaseHelper;
  import com.elan.reader.util.DatabaseHelper_Spa;

  import android.app.ListActivity;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.Chronometer;
  import android.widget.ImageView;
  import android.widget.ListView;
  import android.widget.TextView;


   public class Language extends ListActivity {

 /** Called when the activity is first created. */
private ArrayList<SettingsObject> m_orders = null;
    private AboutAdapter m_adapter;
    private Runnable viewOrders;
    String[] listData={"English","French"};
    //Bitmap[] listImage;
    private Runnable returnRes = new Runnable() {
    @Override
   public void run() {

       if(m_orders != null && m_orders.size() > 0){
           m_adapter.notifyDataSetChanged();
           for(int i=0;i<m_orders.size();i++)
           m_adapter.add(m_orders.get(i));
       }
       m_adapter.notifyDataSetChanged();
   }
 };
    ImageView backBtn;
static boolean running=false;
static long startTime=0;
static Chronometer timer ;
static long  hit_id=-1;
static int stopped=0;
Context me;
   @Override
   public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.title_list_menu);
   me=this;

   DatabaseHelper myDatabaseAdapter;
    myDatabaseAdapter = DatabaseHelper.getInstance(me);
    if(!myDatabaseAdapter.databaseReady()){
        try{
            myDatabaseAdapter.copyDatabase2();
            DatabaseHelper_Spa myDatabaseAdapter_spa =        DatabaseHelper_Spa.getInstance(me);
            myDatabaseAdapter_spa.copyDatabaseSpanish2();

        }catch(Exception e){
            e.printStackTrace();
        }
        myDatabaseAdapter.databaseReady();
    }else{
        //myDatabaseAdapter.close();

        if(myDatabaseAdapter.getSaveVerse()[0]!=null||!myDatabaseAdapter.getSaveVerse()[0].equals("")){
            String data[]=myDatabaseAdapter.getSaveVerse();
           Intent intent=new Intent(Language.this,  Verse.class);
        intent.putExtra("language",data[0]);
        intent.putExtra("volume_id",data[1]);
        intent.putExtra("chapter",data[2]);
        intent.putExtra("book",data[3]);
        intent.putExtra("book_id",data[4]);
        intent.putExtra("multiple_languages",false);
            startActivity(intent);

        }
    }

  // listImage=new Bitmap[]{BitmapFactory.decodeResource(getResources(), R.drawable.sharing),BitmapFactory.decodeResource(getResources(), R.drawable.contact_us),BitmapFactory.decodeResource(getResources(), R.drawable.about)};
   m_orders = new ArrayList<SettingsObject>();
   this.m_adapter = new AboutAdapter(this, R.layout.language_row, m_orders);
   setListAdapter(this.m_adapter);
   viewOrders = new Runnable(){
       @Override
       public void run() {
           getOrders();
       }
   };

   Thread thread =  new Thread(null, viewOrders, "MagentoBackground");
   thread.start();

} }

    @Override
protected void onListItemClick(ListView li, View v, int position, long id) {
    super.onListItemClick(li, v, position, id);
    Intent intent=new Intent(Language.this,  Volume.class);
    intent.putExtra("language",""+position);

    startActivity(intent);


   }


@Override
protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();
    System.out.println("onRestart");
    //loadImages();

  }

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    System.out.println(" onResume");

}

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    System.out.println("onStart");
}
private class AboutAdapter extends ArrayAdapter<SettingsObject> {

   private ArrayList<SettingsObject> items;

   public AboutAdapter(Context context, int textViewResourceId, ArrayList<SettingsObject> items) {
           super(context, textViewResourceId, items);
           this.items = items;
   }

   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
           View v = convertView;
           if (v == null) {
               LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
               v = vi.inflate(R.layout.language_row, null);
           }

           final SettingsObject o = items.get(position);
           if (o != null) {
                   TextView title = (TextView) v.findViewById(R.id.title);
                   if (title != null) {
                    title.setText(o.getName());                            
                   }

           }
           return v;
   }
}
private void getOrders(){
   try{

       m_orders = new ArrayList<SettingsObject>();
       for(int i=0;i<listData.length;i++){
        SettingsObject temp = new SettingsObject(listData[i]);
         m_orders.add(temp);
       }
     } catch (Exception e) { 
      e.printStackTrace();
     }
     runOnUiThread(returnRes);
 }
  class SettingsObject {

    private String name;

    public String getName() {
        return name;
    }
    public SettingsObject(String name) {
        this.name = name;
    }

}

} ` }`

In your settings>>developer options>> select app to be debugged, you should probably just change that to no app, because the app would only start if you have a debugger from eclipse attached to your device. 在设置>>开发人员选项>>选择要调试的应用程序中,您可能应该将其更改为无应用程序,因为只有在您的设备上连接了eclipse调试器时,该应用程序才能启动。 If you change it to No Application, the app can be launched at any time you wish. 如果将其更改为“无应用程序”,则可以在任何时候启动该应用程序。 I hope it helps. 希望对您有所帮助。 :) :)

Try adding Log.d outputs in different parts of the code to follow what is being executed and what does not. 尝试在代码的不同部分中添加Log.d输出,以跟踪正在执行和未执行的内容。

What does myDatabaseAdapter.databaseReady(); myDatabaseAdapter.databaseReady();是什么? do? 做? Why do you have the following code? 为什么会有以下代码?

if(!myDatabaseAdapter.databaseReady()) {
    // try catch bock
    myDatabaseAdapter.databaseReady();
}

What does startActivity(intent); startActivity(intent);是什么? do in the else part of the same if block? 在相同的if块的else部分中做else

Not sure if this is the cause of your problem but in your AndroidManifest.xml you have 2 activity entries for Language. 不知道这是否是造成问题的原因,但是在AndroidManifest.xml中,您有2个针对Language的活动条目。 You should remove the second entry. 您应该删除第二个条目。

<activity android:theme="@android:style/Theme.Light" android:name="Language"></activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Webview 后退按钮不会返回(退出应用程序) - Webview back button won't go back ( Exit app ) 应用无法在设备上启动 - App won't launch on the device 当我按下返回按钮时,我的应用程序不会关闭 - My app won't close when i press the back button 当我离开我的应用程序以更改设备字体并返回我的应用程序时,它崩溃了。 - When I leave my app to change the device font and go back into my app it crashes. 将 Flutter 应用程序连接到 Firebase 后,我无法在物理设备上启动应用程序 - I can't launch app on my physical device after connecting my Flutter app to Firebase 强制通过startActivity启动外部应用程序返回我的应用程序 - Force external app launched via startActivity to go back to my app 单击设备中的后退按钮时退出应用程序 - Exit the app when back button in device is clicked 当我在设备页面和模拟器页面之间来回切换时,为什么我的App的按钮会缩小? - Why are my App's buttons shrinking when I go back & forth between pages on a device versus emulator? 当我尝试在我的应用程序中启动BasicMapActivity时发生ClassNotFoundException - ClassNotFoundException when i try to launch a BasicMapActivity within my App 我重命名了程序包,但我的应用程序无法启动 - I renamed a package and my app won't launch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM