尝试重新加载活动本身时出错

时间:2012-05-31 07:30:10

标签: android android-intent

我正在尝试重新加载活动。 这是代码:

public class CobaGesture extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ImageButton resetBut = (ImageButton) findViewById(R.id.reset);
    resetBut.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(getIntent().setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)); finish();
        }
    });

当我按下resetBut时,一切都还可以,但我的应用程序有点冻结,当我反复触摸屏幕时,力量关闭我来了。 这是logcat:

05-31 14:20:45.370: ERROR/ActivityManager(103): ANR in coba.gesture (coba.gesture/.CobaGesture)
05-31 14:20:45.370: ERROR/ActivityManager(103): Reason: keyDispatchingTimedOut
05-31 14:20:45.370: ERROR/ActivityManager(103): Load: 3.91 / 2.13 / 1.86
05-31 14:20:45.370: ERROR/ActivityManager(103): CPU usage from 15350ms to 0ms ago with 99% awake:
05-31 14:20:45.370: ERROR/ActivityManager(103):   65% 6436/coba.gesture: 63% user + 1.9% kernel / faults: 40 minor
05-31 14:20:45.370: ERROR/ActivityManager(103):   29% 103/system_server: 21% user + 7.8% kernel / faults: 5 minor
05-31 14:20:45.370: ERROR/ActivityManager(103):   0.9% 41/adbd: 0% user + 0.8% kernel / faults: 41 minor
05-31 14:20:45.370: ERROR/ActivityManager(103):   0.2% 6227/com.svox.pico: 0.1% user + 0% kernel / faults: 79 minor
05-31 14:20:45.370: ERROR/ActivityManager(103):   0.1% 476/zygote: 0.1% user + 0% kernel / faults: 84 minor
05-31 14:20:45.370: ERROR/ActivityManager(103):   0.4% 647/com.android.settings: 0% user + 0.4% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):   0.1% 225/com.android.systemui: 0% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):   0% 220/com.android.phone: 0% user + 0% kernel / faults: 14 minor
05-31 14:20:45.370: ERROR/ActivityManager(103): 100% TOTAL: 86% user + 13% kernel + 0.1% softirq
05-31 14:20:45.370: ERROR/ActivityManager(103): CPU usage from 3589ms to 4323ms later:
05-31 14:20:45.370: ERROR/ActivityManager(103):   56% 6436/coba.gesture: 55% user + 1.3% kernel / faults: 12 minor
05-31 14:20:45.370: ERROR/ActivityManager(103):     27% 6446/Thread-10: 27% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     26% 6453/Thread-11: 26% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     1.3% 6441/Compiler: 1.3% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):   38% 103/system_server: 23% user + 14% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     19% 111/SurfaceFlinger: 11% user + 7.4% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     17% 172/InputDispatcher: 8.9% user + 8.9% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     1.4% 265/Binder Thread #: 1.4% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     1.4% 268/Binder Thread #: 1.4% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     1.4% 304/Binder Thread #: 1.4% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):     1.4% 394/Binder Thread #: 1.4% user + 0% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103):   0.7% 647/com.android.settings: 0% user + 0.7% kernel / faults: 1 minor
05-31 14:20:45.370: ERROR/ActivityManager(103):     1.4% 648/HeapWorker: 0% user + 1.4% kernel
05-31 14:20:45.370: ERROR/ActivityManager(103): 100% TOTAL: 80% user + 19% kernel
这是什么意思?怎么解决? 如果您有其他方式重新加载活动,请告诉我。

提前感谢。

1 个答案:

答案 0 :(得分:0)

尝试这样的事情

Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();

overridePendingTransition(0, 0);
startActivity(intent);

我使用它,它工作正常。