2015-03-26 4 views
0

У меня есть приложение с 20 видами деятельности. Когда я запускаю приложение в своем телефоне, оно тихо запускается от 1 до 18 операций. Но в 18-ом действии, когда я нажимаю кнопку «ОК» в предупреждении, мое приложение остановилось. Но когда я нажимаю «ОК», приложение продолжается и возвращает меня к активности 17. И в 18-м действии, когда я нажимаю «ОК» в диалоговом окне, продолжается до 18-го действия.К сожалению приложение приостановлено, но продолжается, когда нажата кнопка ОК.

Но когда я запускаю приложение в свой эмулятор, он отлично работает.

Вот мой код в моей 17 деятельности

public class Luzon8Trivia extends Activity { 
 
\t private Button nextQ8; 
 

 
\t @Override 
 
\t protected void onCreate(Bundle savedInstanceState) { 
 
\t \t super.onCreate(savedInstanceState); 
 
\t \t setContentView(R.layout.luzon8_trivia); 
 
\t \t 
 
\t \t Intent intent=getIntent(); 
 
\t \t int myValue=intent.getIntExtra("parameter name", 0); 
 
\t \t final int answer=myValue + 10; 
 
\t \t nextQ8=(Button)findViewById(R.id.btnNextQuestion); 
 
\t \t nextQ8.setOnClickListener(new OnClickListener() { 
 
\t \t \t 
 
\t \t \t @Override 
 
\t \t \t public void onClick(View arg0) { 
 
\t \t \t \t Intent intent=new Intent(Luzon8Trivia.this, Luzon09.class); 
 
\t \t \t \t intent.putExtra("parameter name", answer); 
 
\t \t \t \t startActivity(intent); 
 
\t \t \t \t overridePendingTransition(R.animator.transition_fade_in, R.animator.transition_fade_out);} 
 
\t \t }); 
 
\t } 
 
}

И вот мой код в 18-активности

public class Luzon09 extends Activity { 
 
\t private int currentQuestion; 
 
\t private String [] answers; 
 
\t private Button answerButton; 
 
\t private TextView scoreTxt, showClue; 
 
\t private EditText answerText; 
 
\t int newCoin, myValue; 
 
\t int newScore, newScore2=0; 
 
\t private Button luz9he1, luz9he2, luz9he3; 
 
\t @Override 
 
\t protected void onCreate(Bundle savedInstanceState) { 
 
\t \t super.onCreate(savedInstanceState); 
 
\t \t setContentView(R.layout.luzon09); 
 
\t \t Intent intent=getIntent(); 
 
\t \t int myValue=intent.getIntExtra("parameter name", 0); 
 
\t \t newCoin=myValue; 
 
\t \t scoreTxt=(TextView)findViewById(R.id.score); 
 
\t \t scoreTxt.setText("" + newCoin); 
 
\t \t 
 
\t \t showClue=(TextView)findViewById(R.id.txtviewClue); 
 
\t \t 
 
\t \t //accepts user input 
 
\t \t answerText=(EditText)findViewById(R.id.AnswerText); 
 
\t \t 
 
\t \t init2(); 
 
\t \t 
 
\t \t luz9he1=(Button)findViewById(R.id.btnLuz1); 
 
\t \t luz9he1.setOnClickListener(new OnClickListener() { 
 
\t \t \t 
 
\t \t \t @Override 
 
\t \t \t public void onClick(View v) { 
 
\t \t \t \t if (newCoin>=10){ 
 
\t \t \t    \t AlertDialog.Builder builder = new AlertDialog.Builder(Luzon09.this); 
 
\t \t \t    builder.setTitle("Need some Help?"); 
 
\t \t \t    builder.setMessage("Using Help will deduct your Peso Coin by 20. Are you sure?"); 
 
\t \t \t    builder.setIcon(android.R.drawable.ic_dialog_info); 
 
\t \t \t    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() { 
 
\t \t \t     public void onClick(DialogInterface dialog, int which) { 
 
\t \t \t     \t newCoin-= 20; 
 
\t \t \t     \t scoreTxt.setText("" + newCoin); 
 
\t \t \t     \t luz9he1.setEnabled(false); 
 
\t \t \t  \t \t \t \t showClue.setText("The province has been known as the Historical Capital of the Philippines"); 
 
\t \t \t     return; } 
 
\t \t \t        });// + 
 
\t \t \t    builder.setNegativeButton("NO", new DialogInterface.OnClickListener() { 
 
\t \t \t \t \t \t \t public void onClick(DialogInterface dialog, int which) { 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t }); 
 
\t \t \t    AlertDialog alert = builder.create(); 
 
\t \t \t \t \t  alert.show(); \t 
 
\t \t \t \t \t } 
 
\t \t \t  \t else {Toast.makeText(Luzon09.this, "You have insufficient coins!", Toast.LENGTH_SHORT).show(); 
 
} 
 
\t \t \t } 
 
\t \t });//end of help 1 
 
\t \t 
 
\t \t luz9he2=(Button)findViewById(R.id.btnLuz11); 
 
\t \t luz9he2.setOnClickListener(new OnClickListener() { 
 
\t \t \t @Override 
 
\t \t \t public void onClick(View v) { 
 
\t \t \t \t if (newCoin>=10){ 
 
\t \t \t \t    \t AlertDialog.Builder builder = new AlertDialog.Builder(Luzon09.this); 
 
\t \t \t \t    builder.setTitle("Need some Help?"); 
 
\t \t \t \t    builder.setMessage("Using Help will deduct your Peso Coin by 20. Are you sure?"); 
 
\t \t \t \t    builder.setIcon(android.R.drawable.ic_dialog_info); 
 
\t \t \t \t    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() { 
 
\t \t \t \t     public void onClick(DialogInterface dialog, int which) { 
 
\t \t \t \t     \t newCoin-= 20; 
 
\t \t \t \t     \t scoreTxt.setText("" + newCoin); 
 
\t \t \t \t  \t \t \t \t luz9he2.setEnabled(false); 
 
\t \t \t \t  \t \t \t \t showClue.setText("It is surrounded by Laguna province to the east, Metro Manila to the northeast, and Batangas province to the south."); 
 
\t \t \t \t     return; } 
 
\t \t \t \t        }); //+ 
 
\t \t \t \t    builder.setNegativeButton("NO", new DialogInterface.OnClickListener() { 
 
\t \t \t \t \t \t \t \t public void onClick(DialogInterface dialog, int which) { 
 
\t \t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t \t }); 
 
\t \t \t \t    AlertDialog alert = builder.create(); 
 
\t \t \t \t \t \t  alert.show(); \t 
 
\t \t \t \t \t \t } 
 
\t \t \t \t  \t else { Toast.makeText(Luzon09.this, "You have insufficient coins!", Toast.LENGTH_SHORT).show(); 
 
} 
 
\t \t \t \t \t } 
 
\t \t \t \t });//end of help 2 
 
\t \t 
 
\t \t luz9he3=(Button)findViewById(R.id.btnLuz111); 
 
\t \t luz9he3.setOnClickListener(new OnClickListener() { 
 
\t \t \t @Override 
 
\t \t \t public void onClick(View v) { 
 
\t \t \t \t if (newCoin>=10){ 
 
\t \t \t \t    \t AlertDialog.Builder builder = new AlertDialog.Builder(Luzon09.this); 
 
\t \t \t \t    builder.setTitle("Need some Help?"); 
 
\t \t \t \t    builder.setMessage("Using Help will deduct your Peso Coin by 20. Are you sure?"); 
 
\t \t \t \t    builder.setIcon(android.R.drawable.ic_dialog_info); 
 
\t \t \t \t    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() { 
 
\t \t \t \t     public void onClick(DialogInterface dialog, int which) { 
 
\t \t \t \t     \t newCoin-= 20; 
 
\t \t \t \t     \t scoreTxt.setText("" + newCoin); 
 
\t \t \t \t  \t \t \t \t luz9he3.setEnabled(false); 
 
\t \t \t \t  \t \t \t \t showClue.setText("It is one of the most industrialized and one of the fastest growing provinces in the country."); 
 
\t \t \t \t     return; } 
 
\t \t \t \t        }); //+ 
 
\t \t \t \t    builder.setNegativeButton("NO", new DialogInterface.OnClickListener() { 
 
\t \t \t \t \t \t \t \t public void onClick(DialogInterface dialog, int which) { 
 
\t \t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t \t }); 
 
\t \t \t \t    AlertDialog alert = builder.create(); 
 
\t \t \t \t \t \t  alert.show(); \t 
 
\t \t \t \t \t \t  } 
 
\t \t \t \t  \t else {Toast.makeText(Luzon09.this, "You have insufficient coins!", Toast.LENGTH_SHORT).show(); 
 
} 
 
\t \t \t \t \t } 
 
\t \t \t \t });//end of help 2 
 

 
\t \t 
 
\t } 
 

 
\t public void onBackPressed() { 
 
\t \t startActivity(new Intent(Luzon09.this, MainMenu.class)); 
 
\t \t finish(); 
 
\t  return; 
 
\t } 
 
\t public void init2() 
 
\t { 
 
\t //correct answer 
 
\t answers=new String[]{"Cavite"}; 
 
\t 
 
\t //accepts user input 
 
\t answerText=(EditText)findViewById(R.id.AnswerText); 
 
\t 
 
\t //checks if the answer is correct 
 
\t answerButton=(Button)findViewById(R.id.AnswerButton); 
 
\t answerButton.setOnClickListener(new OnClickListener() { 
 
\t \t 
 
\t \t @Override 
 
\t \t public void onClick(View v) { 
 
\t \t \t // TODO Auto-generated method stub 
 
\t \t \t checkAnswer(); 
 
\t \t } 
 
\t }); 
 
\t } 
 
\t 
 
\t public boolean isCorrect(String answer) 
 
\t { \t return(answer.equalsIgnoreCase(answers[currentQuestion])); \t } 
 

 
\t public void checkAnswer() 
 
\t { \t String answer=answerText.getText().toString(); \t 
 

 
\t \t if(isCorrect(answer)) 
 
\t \t { \t \t 
 
      AlertDialog.Builder builder = new AlertDialog.Builder(this); 
 
      builder.setTitle("What are you a GENIUS?!"); 
 
      builder.setMessage("Nice one, Genius! You have P10!"); 
 
      builder.setIcon(android.R.drawable.btn_star); 
 
      builder.setPositiveButton("View Trivia",new DialogInterface.OnClickListener() { 
 
      public void onClick(DialogInterface dialog, int which) { 
 
      \t String userData=scoreTxt.getText().toString(); 
 
      \t int userNumber=Integer.parseInt(userData); 
 
      \t Intent intent=new Intent(Luzon09.this, Luzon09Trivia.class); 
 
      \t intent.putExtra("parameter name", userNumber); 
 
      \t startActivity(intent); 
 
      \t overridePendingTransition(R.animator.transition_fade_in, R.animator.transition_fade_out); 
 
      \t ;} }); 
 
      \t AlertDialog alert = builder.create(); 
 
     \t \t  alert.show(); // Show Alert Dialog 
 
     \t \t \t scoreTxt.setVisibility(View.GONE); 
 
     \t \t \t 
 
       //disable all the buttons and textview 
 
     \t \t \t answerText.setEnabled(false); 
 
     \t \t \t answerButton.setClickable(false); \t \t 
 
     \t \t \t \t \t \t } 
 
     \t \t else 
 
     \t \t { 
 
     \t \t \t Toast.makeText(this, "Wrong! Try again", Toast.LENGTH_SHORT).show(); 
 
     \t \t \t } 
 
     \t \t 
 
     \t } 
 
     \t }

Par Наденьте меня на длинный код.

+0

Вы не можете проверить лог-код? Тогда какой смысл использовать этот эмулятор? – m0skit0

+0

Вы компилируете приложение из Android Studio или Intellij? – mmark

+0

нет. Я использую eclipse. я проверю logcat. – Pucckat19

ответ

0

Проверьте Menifest файл, написать ли активность для activity18 или не

<activity android:name="activity_name"></activity> 

и Эмуляция App непосредственно на телефон, вы должны написать

android:installLocation="auto" 

в menofest файле после

android:versionCode="1" 
android:versionName="1.0" 

затем подключите телефон к компьютеру и включите USB-отладку.

+0

деятельность 18 включена. плохо попробуйте свое второе решение. Спасибо. – Pucckat19

Смежные вопросы