【发布时间】:2014-02-26 17:54:34
【问题描述】:
我在这里调用了一个 Activity,它是一个聊天应用程序。
猫日志:
02-26 12:30:38.996: I/Choreographer(807): Skipped 35 frames! The application may be doing too much work on its main thread.
02-26 12:30:39.196: I/Choreographer(807): Skipped 31 frames! The application may be doing too much work on its main thread.
02-26 12:30:39.516: I/Choreographer(807): Skipped 31 frames! The application may be doing too much work on its main thread.
02-26 12:30:39.996: I/Choreographer(807): Skipped 32 frames! The application may be doing too much work on its main thread.
02-26 12:30:40.066: I/Choreographer(807): Skipped 37 frames! The application may be doing too much work on its main thread.
02-26 12:30:40.207: I/Choreographer(807): Skipped 33 frames! The application may be doing too much work on its main thread.
02-26 12:30:40.896: I/Choreographer(807): Skipped 33 frames! The application may be doing too much work on its main thread.
02-26 12:30:41.586: I/Choreographer(807): Skipped 30 frames! The application may be doing too much work on its main thread.
02-26 12:30:42.266: I/Choreographer(807): Skipped 30 frames! The application may be doing too much work on its main thread.
02-26 12:30:42.486: I/Choreographer(807): Skipped 31 frames! The application may be doing too much work on its main thread.
02-26 12:30:42.556: I/Choreographer(807): Skipped 37 frames! The application may be doing too much work on its main thread.
02-26 12:30:42.826: I/Choreographer(807): Skipped 32 frames! The application may be doing too much work on its main thread.
02-26 12:30:43.316: I/Choreographer(807): Skipped 30 frames! The application may be doing too much work on its main thread.
02-26 12:30:43.777: I/Choreographer(807): Skipped 30 frames! The application may be doing too much work on its main thread.
02-26 12:30:43.826: I/Choreographer(807): Skipped 32 frames! The application may be doing too much work on its main thread.
02-26 12:30:43.866: I/Choreographer(807): Skipped 34 frames! The application may be doing too much work on its main thread.
. . . . .
. . . . .
. . . . .
这就是我从 MainActivity 开始活动的方式:
public class MainActivity extends Activity {
Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button1);
handler = new Handler(Looper.getMainLooper());
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final Intent i = new Intent(com.example.mainactivity.MainActivity.this,com.quickblox.sample.chat.ui.activities.SplashActivity.class);
handler.post(new Runnable() {
@Override
public void run() {
startActivity(i);
}
});
如何防止这种情况,调用活动后应用程序挂起。什么问题?
更新:
SplashActivity:
public class SplashActivity extends Activity implements QBCallback {
private static final String APP_ID = "7467";
private static final String AUTH_KEY = "TxRFWfX8tTXQ4gv";
private static final String AUTH_SECRET = "y-QJrO2j69VTaCs";
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
QBSettings.getInstance().fastConfigInit(APP_ID, AUTH_KEY, AUTH_SECRET);
QBAuth.createSession(this);
}
@Override
public void onComplete(Result result) {
progressBar.setVisibility(View.GONE);
if (result.isSuccess()) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
} else {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setMessage("Error(s) occurred. Look into DDMS log for details, " +
"please. Errors: " + result.getErrors()).create().show();
}
}
@Override
public void onComplete(Result result, Object context) {
}
}
更新:
您可以在this 线程中找到详细信息。
【问题讨论】:
-
你不需要发帖
Runnable来做你正在做的事情。 -
你能展示 SplashActivity 的 onCreate() 方法吗?很可能没有及时完成。
-
我认为 Yakiv 是正确的。对 QBSettings 和 QBAuth 的调用最好在后台线程或通过 AsyncTask 运行,以便 onCreate() 可以快速完成。
-
我同意@NigelK,使用 AsyncTask 来执行 HTTP 请求。
-
我试过了,但是这个问题已经被 API @SQLiteNoob 解决了
标签: android