我試圖切換活動。每個活動只有一個圖像視圖,所以我沒有發現它需要顯示xml。這是一個相對簡單的程序。根據IF-STATEMENT,程序應切換到適當的視圖。所有圖像都是72dpi jpegs。失敗使用(空白)字節分配(空白)字節分配免費的57MB,直到OOM
package app.com.example.android.chancetheoracle;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(this, "Think Of Your Question, Then Tap Anywhere.",Toast.LENGTH_LONG).show();
}
public void onClick(View view){
Random answer = new Random();
int ask = answer.nextInt(6) + 1;
if (ask == 1){
Intent intent = new Intent(this, redThree.class);
startActivity(intent);
Toast.makeText(this, "2/5! Click Anywhere To Ask Again.",Toast.LENGTH_SHORT).show();
}
else if (ask == 2){
Intent intent = new Intent(this, greenThree.class);
startActivity(intent);
Toast.makeText(this, "3/5! Click Anywhere To Ask Again.",Toast.LENGTH_SHORT).show();
}
else if (ask == 3){
Intent intent = new Intent(this, greenFour.class);
startActivity(intent);
Toast.makeText(this, "4/5! Click Anywhere To Ask Again.",Toast.LENGTH_SHORT).show();
}
else if (ask == 4){
Intent intent = new Intent(this, redFour.class);
startActivity(intent);
Toast.makeText(this, "1/5! Click Anywhere To Ask Again.",Toast.LENGTH_SHORT).show();
}
else if (ask == 5){
Intent intent = new Intent(this, redFive.class);
startActivity(intent);
Toast.makeText(this, "0/5! Click Anywhere To Ask Again.",Toast.LENGTH_SHORT).show();
}
else if (ask == 6){
Intent intent = new Intent(this, greenFive.class);
startActivity(intent);
Toast.makeText(this, "5/5! Click Anywhere To Ask Again.",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(this, "Think Of Your Question, Then Tap Anywhere.",Toast.LENGTH_LONG).show();
}
}
public static class greenThree extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_green_three);
}
}
public static class redThree extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_red_three);
}
}
public static class greenFour extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_green_four);
}
}
public static class redFour extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_red_four);
}
}
public static class greenFive extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_green_five);
}
}
public static class redFive extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_red_five);
}
}
}
顯然圖像過大(分辨率) – Selvin