我有一个为Android 4.3.1 API18开发的基本Android应用程序。 在我的应用程序中,我使用以下代码启动了StartActivityForResult:
footerView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent =
new Intent(ThisActivityClass.this,OtherActivityClass.class);
startActivityForResult(intent, 1);
}
});
新Activity按预期运行,并使用以下代码将结果返回给第一个Activity:
final Button submitButton = (Button) findViewById(R.id.submitButton);
submitButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent data = new Intent();
data.putExtra("A", "DONT_CARE");
setResult(RESULT_OK,data);
finish();
}
});
返回调用Activity,在onActivityResult中成功收到结果:
@Override
protected void onActivityResult
(int requestCode, int resultCode, Intent data) {
if(resultCode == Activity.RESULT_OK){
switch(requestCode)
{
case 1:
ToDoItem item = new ToDoItem(data);
//...Saving Data from Intent
break;
}
}
}
到目前为止一切顺利。 之后,当前活动按以下顺序调用其方法,这意味着一切正常: 1. onStart() 2. onResume() 注意:onPause \ onStop没有被调用!
从这里出现问题 - 模拟器显示黑屏 - 操作栏可见。
并且调试器在最后一行的doCallbacks方法中的Choreographer.class上停止,在结束括号中:
void doCallbacks(int callbackType, long frameTimeNanos) {
CallbackRecord callbacks;
synchronized (mLock) {
// We use "now" to determine when callbacks become due because it's possible
// for earlier processing phases in a frame to post callbacks that should run
// in a following phase, such as an input event that causes an animation to start.
final long now = SystemClock.uptimeMillis();
callbacks = mCallbackQueues[callbackType].extractDueCallbacksLocked(now);
if (callbacks == null) {
return;
}
mCallbacksRunning = true;
}
try {
for (CallbackRecord c = callbacks; c != null; c = c.next) {
if (DEBUG) {
Log.d(TAG, "RunCallback: type=" + callbackType
+ ", action=" + c.action + ", token=" + c.token
+ ", latencyMillis=" + (SystemClock.uptimeMillis() - c.dueTime));
}
c.run(frameTimeNanos);
}
} finally {
synchronized (mLock) {
mCallbacksRunning = false;
do {
final CallbackRecord next = callbacks.next;
recycleCallbackLocked(callbacks);
callbacks = next;
} while (callbacks != null);
}
}
}
LogCat显示以下输出,注意日志末尾显示的onActivityResult,onStart,onResume的调用:
03-22 08:54:26.308: D/gralloc_goldfish(1224): Emulator without GPU emulation detected.
03-22 08:54:26.588: I/Choreographer(1224): Skipped 41 frames! The application may be doing too much work on its main thread.
03-22 08:54:46.268: I/Lab-UserInterface(1224): Entered footerView.OnClickListener.onClick()
03-22 08:54:46.398: I/Lab-UserInterface(1224): ToDoManagerActivity entered onPause
03-22 08:54:51.039: I/Choreographer(1224): Skipped 40 frames! The application may be doing too much work on its main thread.
03-22 08:54:52.759: I/Choreographer(1224): Skipped 34 frames! The application may be doing too much work on its main thread.
03-22 08:54:56.249: I/Choreographer(1224): Skipped 44 frames! The application may be doing too much work on its main thread.
03-22 08:54:58.758: I/Lab-UserInterface(1224): Entered submitButton.OnClickListener.onClick()
03-22 08:54:59.261: I/Lab-UserInterface(1224): Entered onActivityResult()
03-22 08:56:45.298: I/Lab-UserInterface(1224): ToDoManagerActivity entered onStart
03-22 08:56:45.298: I/Lab-UserInterface(1224): ToDoManagerActivity entered onResume
03-22 08:56:45.338: I/Choreographer(1224): Skipped 27628 frames! The application may be doing too much work on its main thread.
03-22 08:56:45.489: D/dalvikvm(1224): GC_FOR_ALLOC freed 108K, 6% free 3711K/3936K, paused 37ms, total 53ms
我尝试了很多东西,无法提出解决方案: 1.无法在线找到解决方案 2.我用try catch块包装每个方法
您如何描述问题? 活动是否失去了焦点(我想不是)? 前台应用程序进入了一个weired状态? 可以使用哪些其他调试工具来查找问题? 最重要的是,你是否遇到过这个问题\知道如何解决它?
此致 hoshmy