Android问题整理(不断更新ing)
这是大家在学习Android中遇到过的问题,通过高手们解决之后,整理出来的一篇文章,以后陆续还会更新。
希望能对学习Android的各位有所帮助,也可以把你们遇到的问题提出来,大家交流解决。
001.(问题)[ Error in an XML file: aborting build.]
【解决】1.如果是自己新建的.Xml文件,检查有无<?xml version="1.0" encoding="utf-8"?>
2.【project】-clean
002.(问题)在做计算器或者别的有关科学记数法时,常会有判断小数点后面的零的问题,
例如 string a =“1234.123000”去掉后面3个000或者123456.123400去掉2个0
【解决】String trimZero (String str) {
String result = str;
int pos = -1;
if (str != null && !str.equals("") && str.indexOf('.') != -1) {
char[] chs = str.toCharArray();
for ( pos = chs.length-1; pos > 0; pos--) {
if (chs[pos] != '0') {
break ;
}
}
result = new String(chs, 0, pos);
}
return result;
}
003.(问题)怎么实现应用的后台卸载?
【解决】private void setIntentAndFinish(boolean finish, boolean appChanged) {
if(localLOGV) Log.i(TAG, "appChanged="+appChanged);
Intent intent = new Intent();
intent.putExtra(ManageApplications.APP_CHG, appChanged);
setResult(ManageApplications.RESULT_OK, intent);
if(finish) {
finish();
}
}
(packageName 是包的完整名字)
004.(问题)接收数据的activity?
【解决】Intent intent2 = new Intent("android.intent.action.SHOWAPPS");
Bundle bundle = new Bundle();
bundle.putBoolean("show", true);
bundle.putString("test", "Recevice Success");
intent2.putExtra("ShowApps", bundle);
intent2.setClassName("com.android.launcher", "com.android.launcher2.Launcher");
startActivity(intent2);
005.(问题)在Android中获取系统时间?
【解决】public class wwe {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String curentDateAndTime = sdf.format(calendar.getTime());
System.out.println(curentDateAndTime);
}
}
006.(问题)程序没有错误,运行时却弹出这样一个窗口:
The application has stopped unexpectedly.Please try again.
【解决】查看Logcat提示的错误,Window-Open Perspective-DDMS- 查出出错的原因,对症下药。DDMS界面:
1.Devices:可以查看到当前运行的Emulator和其内运行的应用。
2.Emulator control,即仿真器的硬件设置项等;设置当前注册的网络状态(Home,Roaming,
UnRegistered,Searching)数据业务的速度设置;有GSM,GPRS,EDGE,UMTS,HSDPA(3.5G?)还有载入KML
或NMEA文件来模拟GPS数据。
3.还可以查询Threads,Heap,File Explorer、重启adb,抓屏等,其他都是在调用adb。
4.关于Logcat从Windows->Prereference->android->DDMS->Loggin Level进行设置打印等级,不过默认
下只打印入口线程的信息,射频和Tapi的动作信息要通过adb Logcat -b radio打开,os-events相关的
打印通过adb logcat -b events.打开,Log默认被写入到手机的/data/anr/traces.txt文件中。
浙公网安备 33010602011771号