从非活动类创建通知
答
通过上下文中的类,然后创建它通常
答
class A extends Activity{
//required stuff go here
new B().createDialog(A.this);
}
其他类
class B{
public void createDialog(Context context){
//create your dialog or notification here
}
}
答
正如subspider上面所说的,通过上下文到类,你会被罚款:
public class DoSomethingClass {
//Here's a context
private Context _CONTEXT;
//Construct that sets the context
public DoSomethingClass(Context c) {
this._CONTEXT = c;
}
public void createNotification() {
/*
Create the notification as usual, just make sure you alter the following lines:
Intent notificationIntent = new Intent(this, MyClass.class);
Context context = this.getApplicationContext();
^Make sure you alter this into this._CONTEXT above
*/
}
}
我不知道你的意思,你可以发布一些片段吗?谢谢 – Waypoint
@Hmyzak对不起,下次我会尝试示例:(希望你罚款 – PedroAGSantos