Java Code Examples for android.app.Activity#startActivity()

The following examples show how to use android.app.Activity#startActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackgroundModeExt.java    From cordova-plugin-background-mode with Apache License 2.0 5 votes vote down vote up
/**
 * Moves the app to the foreground.
 */
private void moveToForeground()
{
    Activity  app = getApp();
    Intent intent = getLaunchIntent();

    intent.addFlags(
            Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
            Intent.FLAG_ACTIVITY_SINGLE_TOP |
            Intent.FLAG_ACTIVITY_CLEAR_TOP);

    clearScreenAndKeyguardFlags();
    app.startActivity(intent);
}
 
Example 2
Source File: Navigator.java    From DaggerWorkshopGDG with Apache License 2.0 5 votes vote down vote up
/**
 * Go to comic detail screen.
 *
 * @param activity Activity from.
 * @param comicId  int identifier of the comic which will be loaded.
 */
public void goToDetail(Activity activity, int comicId) {
    if (activity != null) {
        Intent intentToLaunch = ComicDetailActivity.getCallingIntent(activity, comicId);
        activity.startActivity(intentToLaunch);
    }
}
 
Example 3
Source File: ActivityUtils.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public static void startTopicActivity(Activity a, Topic t, Category c, String url) {
    L.i("topic category: %s", t.category);
    Intent intent = new Intent(a, TopicActivity.class);
    intent.putExtra(Utils.EXTRA_OBJ, t);
    intent.putExtra(Utils.EXTRA_OBJ_C, c);
    intent.putExtra(Utils.EXTRA_ID, t.id.longValue());
    intent.putExtra(Utils.EXTRA_TITLE, t.title);
    intent.putExtra(Utils.EXTRA_SLUG, t.slug);
    intent.putExtra(Utils.EXTRA_URL, url);
    intent.putExtra(Utils.EXTRA_NUMBER, t.last_read_post_number);
    a.startActivity(intent);
}
 
Example 4
Source File: ListFragmentTag.java    From rss with GNU General Public License v3.0 5 votes vote down vote up
@Override
public
boolean onContextItemSelected(MenuItem item)
{
    // Get the feed url from the FeedItem.
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    FeedItem feedItem = ((ViewFeedItem) info.targetView).m_item;
    String url = feedItem.m_url;

    Activity activity = getActivity();

    switch(item.getItemId())
    {
        case R.id.copy:
            ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
            clipboard.setPrimaryClip(ClipData.newPlainText("Url", url));

            Toast toast = Toast.makeText(activity, getString(R.string.toast_url_copied) + ' ' + url, Toast.LENGTH_SHORT);
            toast.show();
            return true;

        case R.id.open:
            activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            return true;

        case R.id.favourite:
            addToFavourites(activity, feedItem);
            return true;

        case R.id.save_image:
            downloadImage(activity, feedItem.m_imageLink, feedItem.m_imageName);

        default:
            return false;
    }
}
 
Example 5
Source File: CallActivity.java    From BubbleAnimationLayout with MIT License 5 votes vote down vote up
public static void start(Activity activity, View view, String elementName, MainActivity.User user) {
    Intent intent = new Intent(activity, CallActivity.class);
    intent.putExtra(EXTRA_ELEMENT_ID, elementName);
    intent.putExtra(EXTRA_USER, user);
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, elementName);
    activity.startActivity(intent, options.toBundle());
}
 
Example 6
Source File: UI.java    From Android-Commons with Apache License 2.0 5 votes vote down vote up
/**
 * Restarts the given `Activity`
 *
 * @param activity the `Activity` instance to restart (e.g. `MyActivity.this`)
 */
public static void restartActivity(final Activity activity) {
	final Intent restart = new Intent(activity, activity.getClass());
	restart.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

	activity.finish();
	activity.overridePendingTransition(0, 0);
	activity.startActivity(restart);
	activity.overridePendingTransition(0, 0);
}
 
Example 7
Source File: ActivityInvokeAPI.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 打开用户话题列表界面。
 * 
 * @param activity
 * @param uid 用户uid
 */
public static void openUserTrends(Activity activity,String uid){
    if(activity==null){
        return;
    }
    Intent intent=new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory("android.intent.category.DEFAULT");
    intent.setData(Uri.parse("sinaweibo://usertrends?uid="+uid));
    activity.startActivity(intent);
}
 
Example 8
Source File: ActivityManager.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void restartCurrentActivity() {
    final Activity top = getTopActivity();
    if(top instanceof Activity) {
        final Activity ac = (Activity)top;
        Intent i = ac.getIntent();
        boolean rst = false;
        Log.i(TAG, "activity " + ac.getComponentName() + " has singleTask:" + rst);
        i.addFlags(65536);
        ac.overridePendingTransition(0, 0);
        ac.startActivity(i);
        (new Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
            public void run() {
                Log.e(TAG, "first task id " + sFirstTaskId + " top actvitiy id " + ac.getTaskId());
                Activity a = getTopActivity();
                Log.e(TAG, "last top: " + top + " now top :" + a + " activity size :" + getAllActivities().length);
                if (a == ac) {
                    ac.recreate();
                    Log.d(TAG, "restart :" + ac.getComponentName());
                } else {
                    ac.finish();
                    ac.overridePendingTransition(0, 0);
                    Log.d(TAG, "finish :" + ac.getComponentName());
                }

            }
        }, 200L);
    }

}
 
Example 9
Source File: AppStore.java    From socialmediasignup with MIT License 5 votes vote down vote up
private static void goToAppStore(final Activity activity) {
    SupportedAppStore appStore = SupportedAppStore.fromDeviceManufacturer();
    String appStoreUri = appStore.getAppStoreUri();
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(appStoreUri));
    try {
        activity.startActivity(intent);
    } catch (android.content.ActivityNotFoundException e) {
        //should not happen
    }
}
 
Example 10
Source File: AppTools.java    From RxEasyHttp with Apache License 2.0 5 votes vote down vote up
public static void startForwardActivity(Activity context, Class<?> forwardActivity, Bundle bundle, Boolean isFinish, int animin, int animout) {
    Intent intent = new Intent(context, forwardActivity);
    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (bundle != null)
        intent.putExtras(bundle);
    context.startActivity(intent);
    if (isFinish) {
        context.finish();
    }
    try {
        context.overridePendingTransition(animin, animout);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 11
Source File: AdvancedWebView.java    From Android-AdvancedWebView with MIT License 5 votes vote down vote up
/**
 * Opens the given URL in an alternative browser
 *
 * @param context a valid `Activity` reference
 * @param url the URL to open
 * @param withoutTransition whether to switch to the browser `Activity` without a transition
 */
public static void openUrl(final Activity context, final String url, final boolean withoutTransition) {
	final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
	intent.setPackage(getAlternative(context));
	intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

	context.startActivity(intent);

	if (withoutTransition) {
		context.overridePendingTransition(0, 0);
	}
}
 
Example 12
Source File: LabelManageActivity.java    From OpenHub with GNU General Public License v3.0 4 votes vote down vote up
public static void show(@NonNull Activity activity, @NonNull String owner, @NonNull String repo){
    Intent intent = new Intent(activity, LabelManageActivity.class);
    intent.putExtras(BundleHelper.builder().put("owner", owner).put("repo", repo).build());
    activity.startActivity(intent);
}
 
Example 13
Source File: DownloadHandler.java    From JumpGo with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Notify the host application a download should be done, or that the data
 * should be streamed if a streaming viewer is available.
 *
 * @param context            The context in which the download was requested.
 * @param url                The full url to the content that should be downloaded
 * @param userAgent          User agent of the downloading application.
 * @param contentDisposition Content-disposition http header, if present.
 * @param mimetype           The mimetype of the content reported by the server
 * @param contentSize        The size of the content
 */
public void onDownloadStart(@NonNull Activity context, @NonNull PreferenceManager manager, String url, String userAgent,
                            @Nullable String contentDisposition, String mimetype, String contentSize) {

    Log.d(TAG, "DOWNLOAD: Trying to download from URL: " + url);
    Log.d(TAG, "DOWNLOAD: Content disposition: " + contentDisposition);
    Log.d(TAG, "DOWNLOAD: Mimetype: " + mimetype);
    Log.d(TAG, "DOWNLOAD: User agent: " + userAgent);

    // if we're dealing wih A/V content that's not explicitly marked
    // for download, check if it's streamable.
    if (contentDisposition == null
        || !contentDisposition.regionMatches(true, 0, "attachment", 0, 10)) {
        // query the package manager to see if there's a registered handler
        // that matches.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.parse(url), mimetype);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setComponent(null);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            intent.setSelector(null);
        }
        ResolveInfo info = context.getPackageManager().resolveActivity(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
        if (info != null) {
            // If we resolved to ourselves, we don't want to attempt to
            // load the url only to try and download it again.
            if (BuildConfig.APPLICATION_ID.equals(info.activityInfo.packageName)
                || MainActivity.class.getName().equals(info.activityInfo.name)) {
                // someone (other than us) knows how to handle this mime
                // type with this scheme, don't download.
                try {
                    context.startActivity(intent);
                    return;
                } catch (ActivityNotFoundException ex) {
                    // Best behavior is to fall back to a download in this
                    // case
                }
            }
        }
    }
    onDownloadStartNoStream(context, manager, url, userAgent, contentDisposition, mimetype, contentSize);
}
 
Example 14
Source File: NavigationUtil.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
public static void goToGenre(@NonNull final Activity activity, final Genre genre, @Nullable Pair... sharedElements) {
    final Intent intent = new Intent(activity, GenreDetailActivity.class);
    intent.putExtra(GenreDetailActivity.EXTRA_GENRE, genre);

    activity.startActivity(intent);
}
 
Example 15
Source File: PullToRefreshListViewSimpleActivity.java    From StickHeaderLayout with Apache License 2.0 4 votes vote down vote up
public static void openActivity(Activity activity){
    activity.startActivity(new Intent(activity,PullToRefreshListViewSimpleActivity.class));
}
 
Example 16
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
public static void activityStart(Activity activity) {
    Intent intent = new Intent(activity, MainActivity.class);
    activity.startActivity(intent);
}
 
Example 17
Source File: AndroidUtils.java    From android-3D-model-viewer with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void openUrl(Activity activity, String url){
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    activity.startActivity(i);
}
 
Example 18
Source File: VerbInflectionActivity.java    From aedict with GNU General Public License v3.0 4 votes vote down vote up
public static void launch(Activity activity, EdictEntry entry) {
	final Intent intent = new Intent(activity, VerbInflectionActivity.class);
	intent.putExtra(VerbInflectionActivity.INTENTKEY_ENTRY, entry);
	activity.startActivity(intent);
}
 
Example 19
Source File: BaseActivity.java    From BaseProject with MIT License 4 votes vote down vote up
@Override public void startActivity(@NonNull Activity aty, @NonNull Intent it) {
    aty.startActivity(it);
}
 
Example 20
Source File: UiUtils.java    From MVVMArms with Apache License 2.0 2 votes vote down vote up
/**
 * 跳转界面 3
 *
 * @param activity
 * @param homeActivityClass
 */
public static void startActivity(Activity activity, Class homeActivityClass) {
    Intent intent = new Intent(activity.getApplicationContext(), homeActivityClass);
    activity.startActivity(intent);
}