我正在尝试在用户单击按钮时运行活动,并且活动根据铃声音量显示图像。当我出于某种原因执行它时它不起作用。感谢任何帮助。
private void show() {
AudioManager am=(AudioManager)this.getSystemService(AUDIO_SERVICE);
mode=am.getRingerMode();
switch(mode){
case AudioManager.RINGER_MODE_NORMAL:
try{
tv.setBackground(this.getResources().getDrawable(R.drawable.a1));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a2));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a3));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a31));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a4));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a5));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a6));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a7));
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
case AudioManager.RINGER_MODE_SILENT:
case AudioManager.RINGER_MODE_VIBRATE:
try{
tv.setBackground(this.getResources().getDrawable(R.drawable.a7));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a6));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a5));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a4));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a31));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a3));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a2));
Thread.sleep(1000);
tv.setBackground(this.getResources().getDrawable(R.drawable.a1));
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
日志说这样的话 -
09-19 09:12:54.656: W/dalvikvm(555): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
09-19 09:12:54.696: E/AndroidRuntime(555): FATAL EXCEPTION: main
09-19 09:12:54.696: E/AndroidRuntime(555): java.lang.OutOfMemoryError
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.Bitmap.nativeCreate(Native Method)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.content.res.Resources.loadDrawable(Resources.java:1935)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.content.res.Resources.getDrawable(Resources.java:664)
09-19 09:12:54.696: E/AndroidRuntime(555): at Sarath.app.SilencePlzz.Androidzip.show(Androidzip.java:75)
09-19 09:12:54.696: E/AndroidRuntime(555): at Sarath.app.SilencePlzz.Androidzip.onResume(Androidzip.java:28)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.Activity.performResume(Activity.java:4539)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.os.Looper.loop(Looper.java:137)
09-19 09:12:54.696: E/AndroidRuntime(555): at android.app.ActivityThread.main(ActivityThread.java:4424)
09-19 09:12:54.696: E/AndroidRuntime(555): at java.lang.reflect.Method.invokeNative(Native Method)
09-19 09:12:54.696: E/AndroidRuntime(555): at java.lang.reflect.Method.invoke(Method.java:511)
09-19 09:12:54.696: E/AndroidRuntime(555): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-19 09:12:54.696: E/AndroidRuntime(555): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-19 09:12:54.696: E/AndroidRuntime(555): at dalvik.system.NativeStart.main(Native Method)