android startActivity来自服务中的意图 [英] android startActivity from intent in service

查看:66
本文介绍了android startActivity来自服务中的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在服务中使用意图,但是当我尝试这样做时:

i try to use intent in service but when i try this :

Intent intent_facebook = new Intent (this,MainUploadToYoutube.class);
intent_facebook.putExtra("vid", vid);
startActivity(intent_facebook);

在logcat上遇到此错误:

got this error on logcat :

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

所以我从这里尝试过:

服务中的android启动活动

Intent  intent_facebook = new Intent(getBaseContext(), MainUploadToYoutube.class);
intent_facebook.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity( intent_facebook);

但是这什么都不做,我在logcat中也没有得到错误

but this do nothing and i did not get error in logcat

怎么了?

推荐答案

您是否尝试过自己的代码(使用this作为上下文),但是只是在错误提示时添加标志?

Have you tried your own code (using this as context), but just add the flags as the error tells you?

Intent intent_facebook = new Intent (this, MainUploadToYoutube.class);
intent_facebook.putExtra("vid", vid);
intent_facebook.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent_facebook);

这篇关于android startActivity来自服务中的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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