Android examples for android.app:Activity
find Activity From Context
import android.app.Activity; import android.content.Context; import android.content.ContextWrapper; public class Main{ public static Activity findActivityFromContext(Context ctx) { if (ctx != null) { if (ctx instanceof Activity) { return (Activity) ctx; }/*from ww w.j a v a 2 s. c om*/ if (ctx instanceof ContextWrapper) { ContextWrapper cw = (ContextWrapper) ctx; return findActivityFromContext(cw.getBaseContext()); } } return null; } }