我想在SharedPreferences更改时更新远程服务.以下用于API级别8(Android 2.2).
我的活动有一个OnPreferencesChangedListener通过服务绑定对象调用远程服务.远程服务的接口提供了一个prefsChanged(void)由监听器调用的方法.之后,接口方法计算警报触发某些操作的新时间.此时间也保存到SharedPreferences广播并发送.我的活动收到广播,现在可以显示新的提醒时间.活动和远程服务获得SharedPreferences通过静态方法的调用对象GetPrefs(Context),回答PreferenceManager.getDefaultSharedPreferences(Context).
API级别15(Android 4.0.3)停止运行.调试显示远程服务看到其他版本的SharedPreferences持有不同的(较旧的?)值.从活动和远程服务登录时,记录SharedPreferencesImpl对象会显示不同的地址.文件系统仅显示一个共享首选项文件.
这是一个错误还是我的代码巧合地使用了API级别8?任何建议将不胜感激.
import java.text.DateFormat;
import java.util.Date;
public class DatePlus {
public static void main(String[] args) {
Date now = new Date();
//Date now1 = new Date();
Date now2 = new Date();
DateFormat currentDate = DateFormat.getDateInstance();
int count1=10;
int count2=15;
Date addedDate1 = addDays(now2, count1);
Date addedDate2 = addDays(addedDate1, count2);
System.out.println(currentDate.format(addedDate1));
System.out.println(currentDate.format(addedDate2));
}
public static Date addDays(Date d, int days) {
d.setTime(d.getTime() + days * 1000 * 60 * 60 * 24);
return d;
}
}
Run Code Online (Sandbox Code Playgroud)
虽然预期输出不同,但日期addedDate1和addedDate2输出语句都打印相同的日期.
我是java中正则表达式的新手,
我正在逐行读取文件,并尝试string.matches在行的开头使用3个字符,然后使用10个数字.
在textpad中我可以做类似的事情:
^[A-Z][A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
Run Code Online (Sandbox Code Playgroud)
如何将其转换为java regex?
我正在使用异步任务在菜单项单击上设置壁纸但它继续运行并且不会停止.这是我正在使用的代码:
class ImageTask extends AsyncTask<Void, Void, Void> {
Context c;
ProgressDialog pd;
public ImageTask(Context ctx) { this.c=ctx; }
@Override
protected void onPreExecute() {
pd=ProgressDialog.show(c, "Please Wait", "Setting Wallpaper...");
}
public void onPostExecute() {
pd.dismiss();
Toast.makeText(c, "Wallpaper set successfully", Toast.LENGTH_SHORT).show();
}
protected Void doInBackground(Void... params) {
WallpaperManager wm1=WallpaperManager.getInstance(c);
try { wm1.setBitmap(ImageFrag1.bmg1); }
catch (IOException e) { e.printStackTrace(); }
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
并在项目选择功能我这样做:
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.action_wall: {
/*WallpaperManager wm=WallpaperManager.getInstance(getActivity().getApplicationContext());
try{
wm.setBitmap(bmg1);
Toast.makeText(getActivity().getBaseContext(), "Wallpaper set successfully",Toast.LENGTH_SHORT).show(); …Run Code Online (Sandbox Code Playgroud)