《如何编写省电的android应用》由会员分享,可在线阅读,更多相关《如何编写省电的android应用(34页珍藏版)》请在金锄头文库上搜索。
1、?Android? ? ? ? ? ? ? 1.5GHz ? 1.5GHz ? Moto XT928? 1300? ?1. ? 2. ? 3. ? 4. ? 5. ? 6. ? ?1. ? 2. ? 3. ? 4. ? 5. ? 6. ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? URL httpUrl = new URL(url); HttpURLConnection connection = (HttpURLConnection)httpUrl.openConnection(); connection.setConnectTimeout(?)? U
2、RL httpUrl = new URL(url); HttpURLConnection connection = (HttpURLConnection)httpUrl.openConnection(); ?connection.setConnectTimeout(?)? import java.util.zip.GZIPInputStream; HttpGet request = new ? ?HttpGet(“http:/ HttpResponse resp = new ?DefaultHttpClient().execute(request); HttpEntity entity = r
3、esponse.getEntity(); InputStream compressed = entity.getContent(); InputStream rawData = new ?GZIPInputStream(compressed); ? HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, 5000); HttpGet httpget = new ?HttpGet(“http:/ pictures“)
4、; HttpResponse response = httpclient.execute(httpget); Header header = response.getHeaders(“ETag“); ? ? ? ? ? ? String provider = Settings.Secure.getString( context.getContentResolver(),Settings.Secure.LOCATION_PROVIDE RS_ALLOWED); if (provider != null ? LocationManager lManager = (LocationManager)
5、context.getSystemService(Context.LOCATION_SERVICE); lManager .isProviderEnabled(LocationManager.GPS_PROVIDER); ?Override protected void onResume() ? mSensorManager.registerListener(this,mSensorManager.getDefaultS ensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR _DELAY_NORMAL); ? ? ? ? ?mSensorM
6、anager.unregisterListener(this); ? ? ? ?Override protected void onStart() ? mSensorManager.registerListener(this,mSensorManager.getDefaultS ensor(Sensor.TYPE_ACCELEROMETER),SensorManager.SENSOR _DELAY_NORMAL); ? ? ? ? ?mSensorManager.unregisterListener(this); ? ? ? ? ? ? ? XmlPullParserFactory and B
7、itmapFactory Matcher.reset(newString) for regex StringBuilder.setLength(0) ? ApplicationInfo ai; PackageManager mPm? ai = mPm.getApplicationInfo(app.pkgName, 0); app.icon = new SoftReference(ai.loadIcon(mPm); holder.iconView.setImageDrawable(app.icon.get(); ? ai = mPm.getApplicationInfo(app.pkgName,
8、 0); Drawable ?= ai.loadIcon(mPm)? holder.iconView.setImageDrawable(?); ? ComponentName receiver = new ComponentName(context, myReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_EN ABLED, PackageManager.DO
9、NT_KILL_APP) ?SQLiteDatabase db = mHelper.getWritableDatabase(); db.beginTransaction(); ? ? for (int i = 0; i usageHisList.size(); i+) db.insert(?,null, values); ? ?db.setTransactionSuccessful(); ? ? db.endTransaction(); ? ? ? ?.startAnimation(mChargingAnim);? ? ? ? ?.clearAnimation(); ? ? ? ? ? ?.startAnimation(mChargingAnim);? ? ? ? ?.clearAnimation(); ? ?application context ?android?context? application context?activity context? public class ?ctivity extends A