方法一
参考AlarmClock应用,在响应Alarm的同时设置下一个Alarm
方法二
使用PendingIntent.getBroadcast()的requestCode参数。要想注册多几个Alarm服务,标识就要不同~
参考
http://www.eoeandroid.com/viewthread.php?tid=14650&highlight=
参考AlarmClock应用,在响应Alarm的同时设置下一个Alarm
使用PendingIntent.getBroadcast()的requestCode参数。要想注册多几个Alarm服务,标识就要不同~
http://www.eoeandroid.com/viewthread.php?tid=14650&highlight=
使用MSN天气WEB服务查询北京的天气返回的xml文档如下
使用
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20geo.places%20where%20text%3D%22Barrie%20CA%22&format=xml
参考
http://stackoverflow.com/questions/1822650/yahoo-weather-api-woeid-retrieval
参考
http://stackoverflow.com/questions/2093358/receive-a-woeid-by-lat-long-with-yahoos-api
Since: API Level 5
Bits returned by onStartCommand(Intent, int, int) describing how to continue the service if it is killed. May be START_STICKY, START_NOT_STICKY, START_REDELIVER_INTENT, or START_STICKY_COMPATIBILITY.
Constant Value: 15 (0×0000000f)
Since: API Level 5
This flag is set in onStartCommand(Intent, int, int) if the Intent is a re-delivery of a previously delivered intent, because the service had previously returned START_REDELIVER_INTENT but had been killed before calling stopSelf(int) for that Intent.
Constant Value: 1 (0×00000001)
Since: API Level 5
This flag is set in onStartCommand(Intent, int, int) if the Intent is a a retry because the original attempt never got to or returned from onStartCommand(Intent, int, int).
Constant Value: 2 (0×00000002)
Since: API Level 5
Constant to return from onStartCommand(Intent, int, int): if this service’s process is killed while it is started (after returning from onStartCommand(Intent, int, int)), and there are no new start intents to deliver to it, then take the service out of the started state and don’t recreate until a future explicit call to Context.startService(Intent). The service will not receive a onStartCommand(Intent, int, int) call with a null Intent because it will not be re-started if there are no pending Intents to deliver.
This mode makes sense for things that want to do some work as a result of being started, but can be stopped when under memory pressure and will explicit start themselves again later to do more work. An example of such a service would be one that polls for data from a server: it could schedule an alarm to poll every N minutes by having the alarm start its service. When its onStartCommand(Intent, int, int) is called from the alarm, it schedules a new alarm for N minutes later, and spawns a thread to do its networking. If its process is killed while doing that check, the service will not be restarted until the alarm goes off.
Constant Value: 2 (0×00000002)
Since: API Level 5
Constant to return from onStartCommand(Intent, int, int): if this service’s process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then it will be scheduled for a restart and the last delivered Intent re-delivered to it again via onStartCommand(Intent, int, int). This Intent will remain scheduled for redelivery until the service calls stopSelf(int) with the start ID provided to onStartCommand(Intent, int, int). The service will not receive a onStartCommand(Intent, int, int) call with a null Intent because it will will only be re-started if it is not finished processing all Intents sent to it (and any such pending events will be delivered at the point of restart).
Constant Value: 3 (0×00000003)
Since: API Level 5
Constant to return from onStartCommand(Intent, int, int): if this service’s process is killed while it is started (after returning from onStartCommand(Intent, int, int)), then leave it in the started state but don’t retain this delivered intent. Later the system will try to re-create the service. Because it is in the started state, it will guarantee to call onStartCommand(Intent, int, int) after creating the new service instance; if there are not any pending start commands to be delivered to the service, it will be called with a null intent object, so you must take care to check for this.
This mode makes sense for things that will be explicitly started and stopped to run for arbitrary periods of time, such as a service performing background music playback.
Constant Value: 1 (0×00000001)
Since: API Level 5
Constant to return from onStartCommand(Intent, int, int): compatibility version of START_STICKY that does not guarantee that onStartCommand(Intent, int, int) will be called again after being killed.
Constant Value: 0 (0×00000000)
最近做一个日历相关的Widget,需要在日期变化的时候更新Widget的显示。查找Intent的文档,发现貌似ACTION_DATE_CHANGED可以实现我想要的功能。但实际上该Intent并不会发送。
参考
package com.example;
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH) + 1;
int day = calendar.get(Calendar.DAY_OF_MONTH);
for (int i = 0; i < 30; i++) {
long start = System.currentTimeMillis();
String.format("%d-%02d-%02d", year, month, day);
long end = System.currentTimeMillis();
Log.d("Main", "String.format cost time: " + (end - start) + " millis");
}
}
}
05-28 16:03:39.685: DEBUG/Main(15854): String.format cost time: 22 millis
05-28 16:03:39.705: DEBUG/Main(15854): String.format cost time: 15 millis
05-28 16:03:39.725: DEBUG/Main(15854): String.format cost time: 17 millis
05-28 16:03:39.745: DEBUG/Main(15854): String.format cost time: 14 millis
05-28 16:03:39.755: DEBUG/Main(15854): String.format cost time: 14 millis
05-28 16:03:39.775: DEBUG/Main(15854): String.format cost time: 14 millis
05-28 16:03:39.785: DEBUG/Main(15854): String.format cost time: 14 millis
05-28 16:03:39.805: DEBUG/Main(15854): String.format cost time: 14 millis
05-28 16:03:39.825: DEBUG/Main(15854): String.format cost time: 15 millis
05-28 16:03:39.835: DEBUG/Main(15854): String.format cost time: 13 millis
java.lang.String#format 方法在我的G1上面大概会花费 15 millis。
1. 启动模拟器
2. 进入 adb shell
3. cd /data/data, ls 可以看见已安装的应用的数据目录
# ls
com.youdao.dict
com.kingsoft.android
com.keenvim.cnCalendar
…
Remword.Panso
4. cd Remword.Panso/databases, ls 可见当前应用下所有的database files。
# ls
dict
books
wordbook
5. sqlite3 books
# sqlite3 books
sqlite3 books
SQLite version 3.5.9
Enter ".help" for instructions
sqlite> .tables
.tables
CurrentBook WordBook android_metadata
sqlite> select * from WordBook;
select * from WordBook;
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|abbreviation|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|abide|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|abolish|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|absent|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|absorption|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|abstract|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|absurd|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|abundance|1
19e8f16b-bc4f-4a00-ad2b-31ae0d456139|accessory|1
…
main.xml
search.xml
content.xml
footbar.xml
colors.xml
strings.xml