开始针对Android对话框服务 [英] starting a service from dialog box in android

查看:176
本文介绍了开始针对Android对话框服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始从弹出的对话框中后台服务,它只是不为我工作

I'm trying to start a background service from a pop-up dialog and it's just doesn't work for me

这是code打开对话框:

this is the code for opening the dialog box:

reportWrongLang.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentManager fm = getFragmentManager();
            ReportWrongLangDialog Dialog = new ReportWrongLangDialog(imageInfo.getParam("imageId")[0], getApplicationContext());
            Dialog.show(fm, "are_you_sure_dialog");
        }

在ReportWrongLangDialog我现在的储蓄的appContext和imageId

in the ReportWrongLangDialog i am saving the appContext, and the imageId

和的时候pressing报告按钮,我想启动后台服务,将有关图像报告对话框

and in the dialog when pressing the report button I want to start the background service that will report about the image

在code代表的onClick

the code for the onClick

report.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            System.out.println("got imageid: " + imageId);
            Intent intent = new Intent(appContext, ReportImageService.class);
            intent.putExtra("ReportType", "IMAGE_REPORT");
            intent.putExtra("ImageID", imageId);
            intent.putExtra("Extra", "2");
            appContext.startService(intent);
            System.out.println("after service start");
        }
    });

其中ReportImageService.class是,我想启动该服务。
当我pressing报告按钮没有任何反应。

where ReportImageService.class is the service that I want to start. when i'm pressing the report button nothing happens..

有什么可以是问题?我只能假设有一些问题,在ApplicationContext

what can be the problem? I can only assume that there is some problem with the applicationContext

推荐答案

我有同样的问题,我的应用程序。
为我工作的解决方案是:
而不是通过你的背景和更高版本(带getContextApplication()方法)使用它,还有另一种方式来做到这一点,道:

I had the same problem with my app. The solution that worked for me was: instead of passing your context and use it later (with getContextApplication() method), there is another way to do it, pass:

YourActivityName.this

YourActivityName.this

作为你的背景,然后打电话给你的startService()从该对象的方法。

as your context, and then call your startService() method from this object.

这篇关于开始针对Android对话框服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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