当我在emulator上启动应用程序时,我发现以下消息
我看到有很多类似的问题,但每个问题都有不同的解决方案。Tnx很多!
日志猫
12-24 18:11:37.923: I/ActivityThread(1385): Pub com.bogdanskoric.recnik.DictionaryProvider: com.bogdanskoric.recnik.DictionaryProvider
12-24 18:11:38.464: D/dalvikvm(1385): GC_FOR_ALLOC freed 121K, 3% free 8263K/8455K, paused 125ms, total 129ms
12-24 18:11:38.486: I/dalvikvm-heap(1385): Grow heap (frag case) to 9.582MB for 1536016-byte allocation
12-24 18:11:38.594: D/dalvikvm(1385): GC_CONCURRENT freed 2K, 3% free 9761K/9991K, paused 27ms+6ms, total 110ms
12-24 18:11:39.524: I/Choreographer(1385): Skipped 49 frames! The application may be doing too much work on its main thread.
12-24 18:11:39.723: D/gralloc_goldfish(1385): Emulator without GPU emulation detected.
12-24 18:11:41.454: I/Choreographer(1385): Skipped 348 frames! The application may be doing too much work on its main thread.
12-24 18:11:44.463: I/Choreographer(1385): Skipped 59 frames! The application may be doing too much work on its main thread.
12-24 18:11:46.124: I/Choreographer(1385): Skipped 36 frames! The application may be doing too much work on its main thread.
搜索ictionary.java
package com.bogdanskoric.recnik;
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
// handles a click on a search suggestion; launches activity to show word
Intent wordIntent = new Intent(this, WordActivity.class);
wordIntent.setData(intent.getData());
startActivity(wordIntent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.searchable_dictionary, menu);
MenuItem item = menu.findItem(R.id.search);
final SearchView searchView = (SearchView)MenuItemCompat.getActionView(item);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
searchView.setSearchableInfo(info);
searchView.setIconified(true);
int searchDeleteImgId = getResources().getIdentifier("android:id/search_close_btn", null, null);
ImageView searchDeleteImg = (ImageView) searchView.findViewById(searchDeleteImgId);
searchDeleteImg.setImageResource(R.drawable.ic_action_discard);
int searchSrcTextId = getResources().getIdentifier( "android:id/search_src_text", null, null);
EditText searchEditText = (EditText) searchView.findViewById(searchSrcTextId);
searchEditText.setTextColor(Color.WHITE);
searchEditText.setHintTextColor(Color.WHITE);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return true;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
return true;
}
WordActivity.java
public class WordActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.word);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
Uri uri = getIntent().getData();
Cursor cursor = managedQuery(uri, null, null, null, null);
if (cursor == null) {
finish();
} else {
cursor.moveToFirst();
TextView word = (TextView) findViewById(R.id.word);
TextView definition = (TextView) findViewById(R.id.definition);
int wIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_WORD);
int dIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_DEFINITION);
word.setText(cursor.getString(wIndex));
definition.setText(cursor.getString(dIndex));
}
}
字典提供程序。Java语言
公共类DictionaryProvider扩展ContentProvider{String TAG="DictionaryProvider";
public static String AUTHORITY = "com.bogdanskoric.recnik.DictionaryProvider";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/dictionary");
public static final String WORDS_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE +
"/vnd.bogdanskoric.recnik";
public static final String DEFINITION_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE +
"/vnd.bogdanskoric.recnik";
private DictionaryDatabase mDictionary;
// UriMatcher stuff
private static final int SEARCH_WORDS = 0;
private static final int GET_WORD = 1;
private static final int SEARCH_SUGGEST = 2;
private static final int REFRESH_SHORTCUT = 3;
private static final UriMatcher sURIMatcher = buildUriMatcher();
private static UriMatcher buildUriMatcher() {
UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
// to get definitions...
matcher.addURI(AUTHORITY, "dictionary", SEARCH_WORDS);
matcher.addURI(AUTHORITY, "dictionary/#", GET_WORD);
// to get suggestions...
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, REFRESH_SHORTCUT);
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", REFRESH_SHORTCUT);
return matcher;
}
@Override
public boolean onCreate() {
mDictionary = new DictionaryDatabase(getContext());
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
// Use the UriMatcher to see what kind of query we have and format the db query accordingly
switch (sURIMatcher.match(uri)) {
case SEARCH_SUGGEST:
if (selectionArgs == null) {
throw new IllegalArgumentException(
"selectionArgs must be provided for the Uri: " + uri);
}
return getSuggestions(selectionArgs[0]);
case SEARCH_WORDS:
if (selectionArgs == null) {
throw new IllegalArgumentException(
"selectionArgs must be provided for the Uri: " + uri);
}
return search(selectionArgs[0]);
case GET_WORD:
return getWord(uri);
case REFRESH_SHORTCUT:
return refreshShortcut(uri);
default:
throw new IllegalArgumentException("Unknown Uri: " + uri);
}
}
private Cursor getSuggestions(String query) {
query = query.toLowerCase();
String[] columns = new String[] {
BaseColumns._ID,
DictionaryDatabase.KEY_WORD,
/* SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
(only if you want to refresh shortcuts) */
SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID};
return mDictionary.getWordMatches(query, columns);
}
private Cursor search(String query) {
query = query.toLowerCase();
String[] columns = new String[] {
BaseColumns._ID,
DictionaryDatabase.KEY_WORD,
DictionaryDatabase.KEY_DEFINITION};
return mDictionary.getWordMatches(query, columns);
}
private Cursor getWord(Uri uri) {
String rowId = uri.getLastPathSegment();
String[] columns = new String[] {
DictionaryDatabase.KEY_WORD,
DictionaryDatabase.KEY_DEFINITION};
return mDictionary.getWord(rowId, columns);
}
private Cursor refreshShortcut(Uri uri) {
String rowId = uri.getLastPathSegment();
String[] columns = new String[] {
BaseColumns._ID,
DictionaryDatabase.KEY_WORD,
DictionaryDatabase.KEY_DEFINITION,
SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID};
return mDictionary.getWord(rowId, columns);
}
@Override
public String getType(Uri uri) {
switch (sURIMatcher.match(uri)) {
case SEARCH_WORDS:
return WORDS_MIME_TYPE;
case GET_WORD:
return DEFINITION_MIME_TYPE;
case SEARCH_SUGGEST:
return SearchManager.SUGGEST_MIME_TYPE;
case REFRESH_SHORTCUT:
return SearchManager.SHORTCUT_MIME_TYPE;
default:
throw new IllegalArgumentException("Unknown URL " + uri);
}
}
对于任何想找到这个问题答案的人来说,这里有很好的记录:应用程序可能在其主线程上做了太多的工作。
我对Android非常陌生,在我的应用程序中,当我点击添加在碎片类上的按钮时,我在活动上添加了碎片,我在我的日志猫上得到警告,如下所示- 跳过91帧!应用程序可能在其主线程上做了太多工作。 请帮帮我我该怎么解决这个?
我有以下错误 关于它的研究。。。确保使用Runnable尽可能多地在新线程中启动所有内容。但不断地出错。我几乎注释了我所有的代码,但在我开始一个新活动时仍然得到了它。然后,我对第一次活动中的这个mapfragment进行了注释,错误就消失了。因此,错误是由以下代码引起的: 我从Android文档的谷歌地图API中得到了这个。。。有点奇怪,它没有得到优化。如何确保错误消失?我可以延迟mapFragm
我是Android SDK/API环境的新手。这是我第一次试着画一张图/图表。我尝试使用3个不同的免费库在模拟器上运行不同类型的示例代码,但布局屏幕上没有显示任何内容。logcat将重复以下消息: 当我运行与一个许可库的评估副本相关的示例代码时,问题并没有持续存在,并且图表工作了。
您好,我正在开发一个android应用程序,当我尝试从我的应用程序发送电子邮件时,我会遇到这个错误。基于此链接,我在后台发送邮件而不使用意图 我的程序: 当我直接指定收件人的电子邮件地址时,应用程序工作正常。当我将其指定为存储收件人电子邮件地址的字符串数组时,问题就来了。 Logcat显示: 跳过222帧!应用程序可能在其主线程上做了太多工作。 谁能告诉我到底是什么问题?
我的代码可以工作,但我在监视器中有一条异常消息:我/编舞:跳过了37帧!应用程序可能在其主线程上做了太多工作。 我知道这个错误消息意味着我在用户界面线程中做了很多繁重的处理。问题是对我来说,除了向列表视图添加假数据,我在用户界面线程上几乎什么都不做。我正在使用Asyncask发出一个应用编程接口请求,这是我正在做的唯一的“繁重”工作,它不在主线程中。 我把我所有的代码放在这里,但我认为大部分都不是
我正在开发一个日历应用程序,并使用textview作为日历单元格,当我启动应用程序后检查logcat时,我发现来自Choreographer的消息“跳过了76帧!应用程序可能在其主线程上做了太多工作”。我知道我正在创建很多文本视图(120),但如何在不影响应用程序性能的情况下构建日历呢?是否有其他方法可以构建支持活动的日历?