我的应用程序在最初启动到设备时加载,但在我退出应用程序并返回后,它甚至不会尝试启动
好吧,我对 Android 真的很陌生,为了开始工作,我付钱给开发人员为我构建了一个简单的应用程序,现在我正试图深入了解它以理解它。
我试图解决的问题是应用程序进入的初始启动屏幕。我通过进入 Android 清单文件并更改此值来更改此值:
<activity android:label="@string/app_name" android:name="Home">
到此值:
<activity android:label="@string/app_name" android:name="Languages">
当我将应用程序部署到我的设备时,它会加载 Languages 类!问题是,当我离开应用程序然后尝试返回时,它甚至不会尝试启动应用程序,它只是返回到主屏幕。
没有任何东西可以告诉我发生了什么,并且在应用程序最初关闭后附加调试器也不起作用。
有人对可能发生的事情有任何想法吗?
以下是 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>
`
然后这是最初首先启动的 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();
}
}
}`
然后这是我需要首先启动的新类的代码:`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;
}
}
} `
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.
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:
<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! 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:`
<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;
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;
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;
}
}
}
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定这是否是问题的原因,但在 AndroidManifest.xml 中,您有 2 个语言活动条目。您应该删除第二个条目。
Not sure if this is the cause of your problem but in your AndroidManifest.xml you have 2 activity entries for Language. You should remove the second entry.
尝试在代码的不同部分添加 Log.d 输出,以跟踪正在执行的内容和未执行的内容。
myDatabaseAdapter.databaseReady();
的作用是什么?为什么会有下面的代码?startActivity(intent);
在同一个 if 块的else
部分做什么?Try adding Log.d outputs in different parts of the code to follow what is being executed and what does not.
What does
myDatabaseAdapter.databaseReady();
do? Why do you have the following code?What does
startActivity(intent);
do in theelse
part of the same if block?在您的设置>>开发者选项>>选择要调试的应用程序,您可能应该将其更改为无应用程序,因为只有当您的设备连接有来自 eclipse 的调试器时,该应用程序才会启动。如果您将其更改为“无应用程序”,则可以随时启动该应用程序。我希望它有帮助。 :)
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. If you change it to No Application, the app can be launched at any time you wish. I hope it helps. :)