Example usage for android.app Activity getParent

List of usage examples for android.app Activity getParent

Introduction

In this page you can find the example usage for android.app Activity getParent.

Prototype

public final Activity getParent() 

Source Link

Document

Return the parent activity if this view is an embedded child.

Usage

From source file:com.smartnsoft.droid4me.app.ActivityController.java

/**
 * Indicates whether a redirection is required before letting the activity continue its life cycle. It launches the redirected {@link Activity} if a
 * redirection is need, and provide to its {@link Intent} the initial activity {@link Intent} trough the extra {@link Parcelable}
 * {@link ActivityController#CALLING_INTENT} key.
 * //from   ww w .j  av a 2s  .  c  om
 * <p>
 * If the provided {@code activity} implements the {@link ActivityController.EscapeToRedirector} interface or exposes the
 * {@link ActivityController.EscapeToRedirectorAnnotation} annotation, the method returns {@code false}.
 * </p>
 * 
 * <p>
 * Note that this method does not need to be marked as {@code synchronized}, because it is supposed to be invoked systematically from the UI thread.
 * </p>
 * 
 * @param activity
 *          the activity which is being proved against the {@link ActivityController.Redirector}
 * @return {@code true} if and only if the given activity should be paused (or ended) and if another activity should be launched instead through the
 *         {@link Activity#startActivity(Intent)} method
 * @see ActivityController#extractCallingIntent(Activity)
 * @see ActivityController.Redirector#getRedirection(Activity)
 * @see ActivityController.EscapeToRedirector
 * @see ActivityController.EscapeToRedirectorAnnotation
 */
public boolean needsRedirection(Activity activity) {
    if (redirector == null) {
        return false;
    }
    if (activity instanceof ActivityController.EscapeToRedirector || activity.getClass()
            .getAnnotation(ActivityController.EscapeToRedirectorAnnotation.class) != null) {
        if (log.isDebugEnabled()) {
            log.debug("The Activity with class '" + activity.getClass().getName()
                    + "' is escaped regarding the Redirector");
        }
        return false;
    }
    final Intent intent = redirector.getRedirection(activity);
    if (intent == null) {
        return false;
    }
    if (log.isDebugEnabled()) {
        log.debug("A redirection is needed");
    }

    // We redirect to the right Activity
    {
        // We consider the parent activity in case it is embedded (like in an ActivityGroup)
        final Intent formerIntent = activity.getParent() != null ? activity.getParent().getIntent()
                : activity.getIntent();
        intent.putExtra(ActivityController.CALLING_INTENT, formerIntent);
        // Disables the fact that the new started activity should belong to the tasks history and from the recent tasks
        // intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        // intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        activity.startActivity(intent);
    }

    // We now finish the redirected Activity
    activity.finish();

    return true;
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public static void UIAlertLicense(String title, String html, final Activity activity) {

    AlertDialog alertDialog;//w  w w. j  a  va 2  s  .  c o  m
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle(title);
    WebView webview = new WebView(activity);
    webview.setBackgroundColor(Color.BLACK);
    webview.loadData("<font color=\"FFFFFF\">" + html + " </font>", "text/html", "UTF-8");
    alertDialog.setView(webview);

    alertDialog.setButton("I Acknowledge", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (isFirstLaunch()) {
                install();
                onHelp();
                onChangeLog();
            }
            setFirstLaunch();
            return;
        }
    });
    alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            if (isFirstLaunch()) {
                if (activity.getParent() != null) {
                    activity.getParent().finish();
                } else {
                    activity.finish();
                }
            }
        }
    });
    alertDialog.show();
}