如何创建主屏幕快捷方式恢复顶部活动 [英] how create homescreen shortcut to resume top activity

查看:123
本文介绍了如何创建主屏幕快捷方式恢复顶部活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个litlte code以添加一个快捷方式到主屏幕的第运行时间:

I have a litlte code to add a shortcut to homescreen for the first running time:

    Intent shortcutIntent = new Intent(getApplicationContext(),
            SFlashActivity.class);

    shortcutIntent.setAction(Intent.ACTION_MAIN);

    Intent addIntent = new Intent();
    addIntent
            .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "New App");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                    R.drawable.ic_launcher));

    addIntent
            .setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    addIntent
            .putExtra("duplicate", false);
    getApplicationContext().sendBroadcast(addIntent);

不过,上述code,我的应用程序总是althought我的应用程序正在运行启动闪屏。
所以,我怎么可以让主屏幕快捷方式的简历顶。
我注意到,应用程序的快捷方式由谷歌制作上安装随时重新在顶玩。

But with above code, my app always start Splash screen althought my app is running. So how could i make home screen shortcut resume to top activity. I noticed that, app's shortcut made by google play on install always resume the top activity.

感谢这么多!

推荐答案

使用的isTaskRoot()方法
输入以下code片段到你的OnCreate()你的主要活动
下面是一个例子:

Use the isTaskRoot() method Enter the following code snippet to your OnCreate() of your main activity Here is an example:

 @Override public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.splashscreen);              
        if(!isTaskRoot()){
            finish();
            return; 
        }
 }

找到了解决办法这里

这篇关于如何创建主屏幕快捷方式恢复顶部活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆