开始针对Android对话框服务

编程入门 行业动态 更新时间:2024-10-26 20:21:49
本文介绍了开始针对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对话框服务

本文发布于:2023-11-17 06:30:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609159.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对话框   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!