2011-09-06 71 views

回答

4

通過上下文中的類,然後創建它通常

+0

我不知道你的意思,你可以發佈一些片段嗎?謝謝 – Waypoint

+0

@Hmyzak對不起,下次我會嘗試示例:(希望你罰款 – PedroAGSantos

2
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 
} 
} 
2

正如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 
     */ 
    } 
}