Android 如何使设备冻结?

Android 如何使设备冻结?,android,Android,这是一个有点奇怪的问题,然而,我的项目需要这个。我试图通过在自己的onCreate中调用该活动来模拟“内存不足”的效果(这将无限调用该活动),它工作得非常好 // launch this activity again and again making the device freeze and // reboot Intent intent = new Intent(Intent.ACTION_MAIN); intent.setComponent(new Componen

这是一个有点奇怪的问题,然而,我的项目需要这个。我试图通过在自己的onCreate中调用该活动来模拟“内存不足”的效果(这将无限调用该活动),它工作得非常好

// launch this activity again and again making the device freeze and
    // reboot
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(new ComponentName("com.android.systemmanager",
            "com.android.systemmanager.FreezeScreen1"));
    startActivity(intent);
但这里的问题是我不想使用任何类。我想在广播接收器的onReceive中执行此操作。在没有任何类可调用的情况下,如何实现这一点

是否有其他方法使设备冻结


我还使用AlarmManager每秒调用onReceive。这将有助于加快冷冻过程

一种解决方案可能是:

@Override
public void onReceive(Context context, Intent intent) {
     ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
     final int TOTAL_BITMAPS = 1000; //any large number would work.
     for(int i=0; i<TOTAL_BITMAPS; i++){
          Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.large_image); // load a large bitmap from drawable..
          bitmapArray.add(bitmap);
     }
}
@覆盖
公共void onReceive(上下文、意图){
ArrayList bitmapArray=新的ArrayList();
final int TOTAL_bitmap=1000;//任何大的数字都可以。

对于(int i=0;i一种解决方案可能是:

@Override
public void onReceive(Context context, Intent intent) {
     ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
     final int TOTAL_BITMAPS = 1000; //any large number would work.
     for(int i=0; i<TOTAL_BITMAPS; i++){
          Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.large_image); // load a large bitmap from drawable..
          bitmapArray.add(bitmap);
     }
}
@覆盖
公共void onReceive(上下文、意图){
ArrayList bitmapArray=新的ArrayList();
final int TOTAL_bitmap=1000;//任何大的数字都可以。
对于(int i=0;i创建此方法

private void stackOverFlow()
{
    this.stackOverFlow();
}
然后,只要您想让应用程序冻结,就调用此方法。

创建此方法

private void stackOverFlow()
{
    this.stackOverFlow();
}

然后,在希望应用程序冻结时调用此方法。

在循环中创建
位图将起作用。获得10个大小超过3 MB的超大图像。在帧动画中使用它们。在构建动画对象时,它将抛出内存错误。或者只分配100万整数的数组(每次消耗4MB)。保留对它们的引用,这样它们就不会被垃圾收集。只需将像10mb这样的全高清图像放入nodpi,或者使用图像加载程序加载它而不调整大小都德我刚才说我想让应用程序尽可能小。10mb是巨大的创建
位图
在一个循环中就可以了。获取10个真正巨大的图像,其大小超过3MB。在帧中使用它们动画。在构建动画对象时,它会抛出OutOfMemory错误。或者只分配100万个整数的数组(一次消耗4MB)。保留对它们的引用,这样它们就不会被垃圾收集。只需将全高清图像(如10mb)放入nodpi,或使用图像加载程序(无需调整大小)加载。都德,我刚才说我想让应用程序尽可能小。10mb是巨大的。如果应用程序强制关闭,我的应用程序将被捕获。它会强制关闭吗?应用程序将由
android
系统关闭由于内存不足错误。但如果广播新事件,它将再次运行。嘿,如果应用程序强制关闭,我的应用程序将被捕获。它会强制关闭吗?由于内存不足错误,
android
系统将关闭应用程序。但如果广播新事件,它将再次运行。