我想从对话框选择器到这样的文本文件记录唤醒时间和休眠时间,但调用方法commitToFile2不会附加文本文件"savedData.txt".
我知道这段代码非常脏.我是Java的新手,所以任何其他建议都将不胜感激.
package com.buttinyourface;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.AdapterView.OnItemClickListener;
public class SettingsActivity extends Activity {
public int wakeHour;
public int wakeMinute;
public int sleepHour;
public int sleepMinute;
public String sleepHourText = "No Data";
public String sleepMinuteText = …Run Code Online (Sandbox Code Playgroud) 可能重复:
类型名称后的括号是否与new有所不同?
所以我在我的主要:
Class* pC = new Class;
Run Code Online (Sandbox Code Playgroud)
它的工作原理是
Class* pC = new Class();
Run Code Online (Sandbox Code Playgroud)
我今天才意识到我省略了括号(所以我在某种程度上被最令人烦恼的解析的"对立"所击中).
我的问题:这两种形式是否相同?
我正在使用AlarmManager设置重复意图,但它已经造成一些小问题,所以希望任何人都可以提供帮助.
摘要
有2个未决意图.一个运行在1000,另一个运行在每天2000.每个包含来自数据库的行id以用于识别目的.代码看起来像这样:
Intent i = new Intent(mContext, ScheduleReceiver.class);
i.putExtra(RuleDBAdapter.KEY_ROWID, (int)taskId);
PendingIntent pi =PendingIntent.getBroadcast(...);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);
Run Code Online (Sandbox Code Playgroud)
删除:
问题是我们需要删除其中一个.删除待处理意图的正确方法是设置相同的意图,然后从AlarmManager调用cancel.
Android文档:
public void cancel(PendingIntent operation)
删除具有匹配Intent的所有警报.任何类型的警报,其Intent与此匹配的警报(由filterEquals(Intent)定义)将被取消.public boolean filterEquals(Intent other)
确定两个意图是否相同以进行意图解析(过滤).也就是说,如果他们的行为,数据,类型,类别和类别是相同的.这不会比较意图中包含的任何额外数据.
所以在上面的例子中,如果我做出相同的意图然后取消,上述两个意图将被取消,因为它们来自同一个类/相同的动作等(除了"额外"数据是rowId但filterEquals不关心额外数据).
这有什么解决方法吗?
我有一个git存储库master和alt分支.alt分支包含修改后的master代码版本,我正在尝试将更改合并master到alt这样:
git merge --squash master
Run Code Online (Sandbox Code Playgroud)
合并导致冲突:
Auto-merging myproject/foo/bar
CONFLICT (content): Merge conflict in myproject/foo/bar
Squash commit -- not updating HEAD
Automatic merge failed; fix conflicts and then commit the result.
Run Code Online (Sandbox Code Playgroud)
在我解决冲突并提交更改之后,一切似乎都很好,但是当我git merge --squash master再次运行时(不对任何分支进行任何更改)我将得到相同的冲突错误.
这是为什么?我错过了什么?
我试图检测何时在目录中创建具有给定名称的文件.我正在这样做,感谢看门狗.正确检测到创建但我不知道如何在检测完成后正确终止应用程序.
我的代码如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import sys
import time
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
logging.basicConfig(level=logging.ERROR)
class MyEventHandler(FileSystemEventHandler):
def __init__(self, observer, filename):
self.observer = observer
self.filename = filename
def on_created(self, event):
print "e=", event
if not event.is_directory and event.src_path.endswith(self.filename):
print "file created"
self.observer.unschedule_all()
self.observer.stop()
def main(argv=None):
path = argv[1]
filename = argv[2]
observer = Observer()
event_handler = MyEventHandler(observer, filename)
observer.schedule(event_handler, path, recursive=False)
observer.start()
observer.join()
return 0
if __name__ == "__main__": …Run Code Online (Sandbox Code Playgroud) 我setAdapter()在一个扩展的类中调用该方法Fragment.请注意,我已导入android.support.v4.app.Fragment.
但是我收到一个错误,指出API级别必须是11级.
我有什么做的,这样我可以解决这个问题不改变minSdkVersion="8",以minSdkVersion="11"
package foo.bar.qux;
import java.util.Calendar;
import java.util.Date;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class TabFragmentList extends Fragment {
String category, xml;
NodeList nodes;
int numResults;
private ListView lv;
Date date;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) return null;
return (LinearLayout) inflater.inflate(R.layout.eventlist, container,
false);
} …Run Code Online (Sandbox Code Playgroud) 我希望我的应用能够打开屏幕并显示我的应用程序.假设我正在设置闹钟,每小时我都希望我的应用在设备自然睡眠前显示2分钟.
我看到不推荐使用WakeLock(FULL_LOCK)和KeyguardManager.
我创建了一个WakefulBroadcastReceiver和服务,这些都在工作.
@Override
protected void onHandleIntent(Intent intent) {
// I need to show the screen here!
for (int i=0; i<5; i++) {
Log.i("SimpleWakefulReceiver", "Running service " + (i + 1)
+ "/5 @ " + SystemClock.elapsedRealtime());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
Log.i("SimpleWakefulReceiver", "Completed service @ " +
SystemClock.elapsedRealtime());
SimpleWakefulReceiver.completeWakefulIntent(intent);
}
Run Code Online (Sandbox Code Playgroud)
如何以编程方式打开屏幕,过去锁定并从IntentService显示我的活动?
谢谢
我有这个描述服务的代码:
public class navigation_web extends Service {
Context context;
public void navigation() {
Cursor mCur = getContentResolver().query(Browser.BOOKMARKS_URI,
Browser.HISTORY_PROJECTION, null, null, null);
mCur.moveToFirst();
if (mCur.moveToFirst() && mCur.getCount() > 0) {
while (mCur.isAfterLast() == false) {
Log.v("titleIdx",
mCur.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX));
Log.v("urlIdx",
mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX));
mCur.moveToNext();
}
}
// Browser.clearSearches(getContentResolver());
}
public void onCreate() {
// Browser.clearHistory(getContentResolver());
// Browser.clearSearches(getContentResolver());
navigation();
// super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 我想创建几个启动活动(或刷新它)以显示产品描述的通知.
Notification notification = new Notification(R.drawable.applicationicon,
Resources.getString("NewSaleNotification", context),
System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context, MainApplication.class);
intent.putExtra("saleid", saleid);
// to be sure the activity won't be restarted
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, SaleTitle, SaleMessage, pendingIntent);
notificationManager.notify(saleid, notification);
Run Code Online (Sandbox Code Playgroud)
当我创建PendingIntent时,我有4个选择:FLAG_CANCEL_CURRENT,FLAG_NO_CREATE,FLAG_ONE_SHOT和FLAG_UPDATE_CURRENT.
最后一个(http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT)的定义是我想要做的,但它不能正常工作.如果我创建2个通知,它们都具有相同的'saleid'额外,这是最新的.如何使用不同的'saleid'额外制作多个通知?
嗨,我已经能够显示我的活动的通知,当用户点击通知时,应用程序重新启动.但是我只是希望它重新出现而不是重启.例如.它是一个Web应用程序,我希望它在用户选择通知时出现在前面..但不刷新网页.我可以捕获这个意图还是我发错了意图?通常,如果我按下主页按钮并单击应用程序图标,应用程序就会出现并且不会刷新/重新启动.所以这就是我想要的行为.有任何想法吗 ?
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)
getSystemService(ns);
//2.Instantiate the Notification
int icon = R.drawable.notification_icon;
CharSequence tickerText = "My App"; // temp msg on status line
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_ONGOING_EVENT;
//3.Define the Notification's expanded message and Intent:
Context context = getApplicationContext();
CharSequence contentTitle = "Notification";
CharSequence contentText = "My app!"; // message to user
Intent notificationIntent = new Intent(this, HelloAndroid2.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0); …Run Code Online (Sandbox Code Playgroud) notifications android background foreground android-pendingintent
android ×7
alarmmanager ×1
append ×1
background ×1
c++ ×1
constructor ×1
exit-code ×1
file ×1
foreground ×1
git ×1
git-branch ×1
git-merge ×1
new-operator ×1
parsing ×1
python ×1
repeat ×1
service ×1
termination ×1
text ×1
watchdog ×1