Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.support.annotation.NonNull;

public class Main {
    @NonNull
    public static Activity unwrapActivity(@NonNull Context startFrom) {
        while (startFrom instanceof ContextWrapper) {
            if (startFrom instanceof Activity) {
                return ((Activity) startFrom);
            }
            startFrom = ((ContextWrapper) startFrom).getBaseContext();
        }
        throw new IllegalStateException("This Context can't be unwrapped to an Activity!");
    }
}