My android app needs to show a dialog after a delay. The problem is that by the time the dialog is displayed, the context may have changed. 

How can I solve this problem?

My code right now looks like this:

```
class UpdateRunnable extends Runnable {
    private Context ctx;
    UpdateRunnable(Context ctx) {
        this.ctx = ctx
    }
    @Override
    public void run() {
        //throws exception: "Unable to add window -- token null is not for an application"
        AlertDialog.Builder builder = new AlertDialog.Builder(ctx.getApplicationContext());
        builder.setTitle("Time to refresh data");
        builder.setMessage("Data needs updating");
        builder.show();
    }
}

class MyAvtivity extends AppCompatActivity {
    @override
    public void onCreate(...) {
        Handler updateHandler = new Handler();
        updateHandler.postDelayed(new UpdateRunnable(this), 10000);

        //do some stuff
        //start another activity
    }
}

```