问题是:“跳过100帧!应用程序可能在其主线程上做了太多工作。”
我可以解决问题吗?
对不起,如果这很简单,我是新手,我正在学习
MainActivity.java
package com.ahora.si;
import java.util.Date;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import android.app.Activity;
import android.database.Cursor;
import android.provider.CallLog;
import android.util.Log;
import android.app.AlertDialog;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getCallDetails();
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void getCallDetails() {
StringBuffer sb = new StringBuffer();
Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
null, null, null);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
sb.append("Call Log :");
while (managedCursor.moveToNext()) {
String phNumber = managedCursor.getString(number);
String nombre = managedCursor.getString(name);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String callDuration = managedCursor.getString(duration);
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
sb.append("\nPhone Number: " + phNumber + " \nNombre: " + nombre + " \nCall Type: "
+ dir + " \nCall Date:--- " + callDayTime
+ " \nCall duration in sec :--- " + callDuration);
sb.append("\n----------------------------------");
}
Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();
//managedCursor.close();
Log.d("TESTTT", sb.toString());
}
}
谢谢! 此致!
答案 0 :(得分:3)
您在主应用程序线程上使用ContentProvider
。这意味着间接地,您在主应用程序线程上执行磁盘I / O,这对您的UI不利。
使用CursorLoader
或以其他方式将query()
逻辑移动到后台线程中,例如通过一条评论中建议的AsyncTask
。