我正在创建一个触发Intent的通知.这是我的代码的一个非常简短的摘录......
Notification notification = new Notification(R.drawable.icon, "notification", System.currentTimeMillis());
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(BackgroundService.this, ConnectionHandler.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, getString(R.string.notification_title), getString(R.string.notification_body), pendingIntent);
notification.flags |= notification.FLAG_AUTO_CANCEL;
nm.notify(1, notification);
Run Code Online (Sandbox Code Playgroud)
在我的意图(ConnectionHandler.class)中,我想展示一个有效的AlertDialog.但我希望在不打开新的UI窗口的情况下显示AlertDialog.对我来说最好的是,当点击通知条目时,AlertDialog只显示其他任何内容.
任何想法都表示赞赏.
此致,托比
我缩短的简化课程如下:
class A
{
public:
// ...
methodA();
methodB();
protected:
mutable boost::mutex m_mutex;
sometype* m_myVar;
}
A::methodA( int someParam )
{
boost::mutex::scoped_lock myLock(m_mutex);
m_myVar->doSomethingElse();
}
A::methodB( int someParam )
{
boost::mutex::scoped_lock myLock(m_mutex);
m_myVar->doSomething();
this->methodA(someParam);
}
Run Code Online (Sandbox Code Playgroud)
我想同步访问m_myVar.在调用时A::methodB(),线程会使用相同的互斥锁两次进入锁定状态,并且明显会阻塞第一行A::methodA()
有没有办法在再次传递时scoped_lock不阻止同一个线程?
当然,我只是可以打电话m_mutex.unlock().但这也会释放其他线程等待锁定 - 这绝对不是我想要的.
任何的想法?
最好的问候托比亚斯
有人知道如何在Outlook 2007中以编程方式启用/禁用外出自动响应程序的实际状态吗?
已经在VS 2008中搜索了对象浏览器并找到了枚举Microsoft.Office.Interop.Outlook.OlBusyStatus但我没有找到任何类或其他任何使用它的内容.
任何想法都表示赞赏,感谢和问候
我有一个名为Element的基类.其他一些类(如Label和Image)都扩展了这个类.
我现在有一个调度类,有以下方法:
public class Dispatcher {
public static AbstractPropertyEditor<Label> createEditor(Label e) {
...
}
public static AbstractPropertyEditor<Element> createEditor(Element e) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
如果现在我有一个Label实例(扩展了Element)并且我想将它传递给createEditor(),为什么最通用的方法(第二个)被调用?调用最具体的方法(createEditor(Label e))是不正常的?
我绝对需要使用Element-param的方法来"捕获"a)实现Element但在此调度类中没有自己的特定方法的所有类.
我正在使用Java 6,如何"修复"这个?
编辑:好的,我不得不承认它根本不是关于泛型.但那是我第一次遇到它的地方.
感谢致敬
我试图用C++和X11创建一个完全透明的窗口.它不应该消耗任何事件,只是将它们转发到下面的窗口.某种类型的GlassPane,因为它以Java-Windows而闻名,但是全屏.然后我想画这个窗口.
X11在某种程度上可能吗?
我的第一次尝试是忽略所有事件,只需使用XGetImage()... 从根窗口复制图像.但首先,这是非常慢的,因为窗口需要全屏.XShmGetImage不幸的是,这里不是一个选择.
当然,这个窗口不需要任何装饰,但这不是一个大问题.
如何仅使用X11/Xlib执行此操作?如果不可能,我还需要什么?
任何帮助表示赞赏!
PS:Xinerama被激活Compiz,如果这会带来问题,我可以将它们停用.
我有一个方法返回一个List<Property<?>>.
属性是具有一个通用参数的类型:
public class Property<T extends Comparable<T>> { ... }
Run Code Online (Sandbox Code Playgroud)
有一个混合类型属性的列表,我不知道具体元素具有什么类型参数.
我想做那样的事情:
List<Property<?>> list = getList();
for(Property<?> crt : list)
{
PropertyWrapper<?> crtWrapper = new PropertyWrapper(crt.getGenericType());
// I know this doesn't exist ----^
}
Run Code Online (Sandbox Code Playgroud)
在一句话中:我需要PropertyWrapper具有与当前相同的通用模板参数Property.有没有办法做到这一点?
我可以应用/sf/answers/240655131/中所述的建议,但即使我这样做,如何实现适当的,PropertyWrapper<XXX>然后只有一个实例Class<T>?
Property<?>如果需要,我可以修改.我也不介意是否需要使用反射(我认为它需要)
编辑:我忘记了什么.事实上,我无法通过线路实现包装
PropertyWrapper<?> crtWrapper = new PropertyWrapper(crt.getGenericType());
Run Code Online (Sandbox Code Playgroud)
因为我有专门的子类(PropertyWrapper_String).
现在我看到两种可能性:
1:按字符串对类进行Instanciate:
String strGenericType = "";
Class<?> wrapperClass = Class.forName("PropertyWrapper_" + strGenericType);
Run Code Online (Sandbox Code Playgroud)
2:有没有办法在不创建子类的情况下专门化泛型类?
非常感谢您的提示
在Eclipse Luna的Windows 8 64位机器上,我使用JPA(EclipseLink 2.5.x)和Apache Derby作为JDBC连接.
到目前为止我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="ReportWriter" transaction-type="RESOURCE_LOCAL">
<class>com.example.Clazz</class>
<class>com.example.CommentBank</class>
<class>com.example.CommentCategory</class>
<class>com.example.CourseWork</class>
<class>com.example.GradeModel</class>
<class>com.example.Pupil</class>
<class>com.example.PupilCoursework</class>
<class>com.example.Report</class>
<class>com.example.Year</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:D:\rwdb.db"/>
<property name="javax.persistence.jdbc.user" value="rwdbuser"/>
<property name="javax.persistence.jdbc.password" value="rwdbpassword"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="eclipselink.jdbc.exclusive-connection.is-lazy" value="true"/>
</properties>
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
使用该向导,我在Eclipse中创建了一个新的数据库连接,该连接运行良好.
当我想做JPA Tools=>时Generate Tables From Entities,eclipse开始创建表格......并且永远持续下去.没有例外,没有其他消息,它只是阻止此操作.
我甚至无法取消它.如果我尝试这样做,它只是将"取消请求"添加到该项目并继续.关闭日食也是不可能的,因为它正在等待其当前运营的结束.
.metadata\.log 不包含任何有关此内容的新信息.
哦,我选择"sql-script"作为输出,以防万一.
有任何想法吗?
假设我有一个结构体,它应该用作上传的结果:
type uploadResult struct {
Filename string `json:"filename"`
Code string `json:"code"`
Reason string `json:"reason"`
}
Run Code Online (Sandbox Code Playgroud)
还会有其他类似的结构体,它们都有一个字段Code和另一个名为Reason. 因此,拥有类似通用接口(伪代码;这个不起作用)之类的东西会很有趣:
type apiResult interface {
Code string `json:"code"`
Reason string `json:"reason"`
}
Run Code Online (Sandbox Code Playgroud)
因为我想调用一个函数来提取一些常见的字段,但只提取那些常见的字段:
func failExit(result apiResult) {
fmt.Println(result.Reason)
}
Run Code Online (Sandbox Code Playgroud)
那么我将如何重写它以使其符合我的期望?
此致
我想拥有当前聚焦窗口的宽度和高度.窗户的选择就像一个魅力,而高度和宽度总是返回1.
#include <X11/Xlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
Display *display;
Window focus;
XWindowAttributes attr;
int revert;
display = XOpenDisplay(NULL);
XGetInputFocus(display, &focus, &revert);
XGetWindowAttributes(display, focus, &attr);
printf("[0x%x] %d x %d\n", (unsigned)focus, attr.width, attr.height);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这不是"真正的"窗口,而是当前活动的组件(如文本框或按钮?)为什么它的大小为1x1呢?如果是这种情况,我如何让应用程序的主窗口包含此控件?意味着...有点顶级窗口,除了根窗口之外的最顶层窗口.
PS:不知道这是否真的很重要; 我使用Ubuntu 10.04 32和64位.
显然,我的代码中存在竞争条件.但我无法找到它,因为我很确定要正确同步.经过几个小时的调试,你可能会帮我找到它.
首先,这是我的(非常简化的)代码:
package main
import (
"log"
"time"
)
type Parser struct {
callback Callback
callbackSet chan bool
test int
}
func NewParser() Parser {
p := Parser{}
p.test = 100
p.callbackSet = make(chan bool)
return p
}
func (p *Parser) SetCallback(newCallback Callback) {
log.Println("=> SET CALLBACK: ", newCallback)
p.test = 100
p.callback = newCallback
log.Println("=> SETTING CALLBACK DONE")
p.callbackSet <- true
}
func (p *Parser) StartParsing() {
go p.parse()
}
func (p *Parser) parse() {
cb := <-p.callbackSet
_ …Run Code Online (Sandbox Code Playgroud) c++ ×3
java ×3
go ×2
xlib ×2
android ×1
boost-mutex ×1
c ×1
c# ×1
eclipse ×1
eclipselink ×1
generics ×1
glasspane ×1
goroutine ×1
inheritance ×1
invocation ×1
jpa ×1
office-2007 ×1
overloading ×1
scoped-lock ×1
type-erasure ×1
x11 ×1
xorg ×1