Android undefined intent constructor错误?
本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术。在Android中启动Service时出现“undefined
intent constructor”的错误,怎么办?

我在Activity中尝试启动Service,但出现“undefined intent constructor”的报错信息。
MyService.java代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
public@Overridepublic return;}public returnnull; }@Overridepublic Toast.makeText(this,"My, Log.d(TAG,"onCreate"); instancethis;}@Overridepublic Toast.makeText(this,"My, Log.d(TAG,"onDestroy"); instancenull;}@Overridepublic Toast.makeText(getBaseContext(),"Service,Toast.LENGTH_SHORT).show(); }} |
启动SampleService.java的代码如下:
|
1
2
3
4
5
6
7
8
9
|
public@Overrideprotected super.onCreate(savedInstanceState); setContentView(R.layout.grid_activity); Intentnewthis,MyService.this);//Error startService(myintent); } } |
在manifest file中设定service的初值如下:
|
1
|
<service"true""com.MyApp.MyService" |
请大家帮我解决这个错误。
(最佳答案)
你不应该使用Service.this,而应该按如下方法改变class:
|
1
|
Intentnewthis,MyService.Class); |
做如下调整:
|
1
|
Intentnewthis,MyService.this); |
变为:
|
1
2
|
Intentnewthis,MyService.Class); // |
你没有设置类似于Intent(SampleService, MyService)的构造函数,在intent constructor参数设定上出现错误。
|
1
2
3
4
5
6
7
8
9
10
|
publicAddedinCreatefornull,withforforthis.ParameterspackageContext thisclsThefor |
文章选自StackOverFlow社区,鉴于其内容对于开发者有所帮助,现将文章翻译于此,供大家参考及学习。9Tech将每日持续更新,读者可点击StackOverflow(简称:SOF)精选问答汇总,查看全部译文内容。同时,我们也招募志同道合的技术朋友共同翻译,造福大家!报名请发邮件至zhangqi_wj@cyou-inc.com。
Android undefined intent constructor错误?的更多相关文章
- android 图片叠加效果——两种方法的简介与内容 ,带解决Immutable bitmap passed to Canvas constructor错误
第一种是通过canvas画出来的效果: public void first(View v) { // 防止出现Immutable bitmap passed to Canvas constructor ...
- android之intent显式,显式学习
intent,意图 当从一个Activity到另一个Activity时调用,这里重点学习显式,隐式的使用 使用语句上的区别: 隐式意图: 显式意图: setAction ...
- 【转】【Java/Android】Intent的简介以及属性的详解
一.Intent的介绍 Intent的中文意思是“意图,意向”,在Android中提供了Intent机制来协助应用间的交互与通讯,Intent负责对应用中一次操作的动作.动作涉及数据.附加数据进行描述 ...
- (转载)android开发常见编程错误总结
首页 › 安卓开发 › android开发 android开发常见编程错误总结 泡在网上的日子 / 文 发表于2013-09-07 13:07 第771次阅读 android,异常 0 编辑推荐:稀 ...
- Android 笔记 Intent and Bundle day7
学习了Intent与Bundle的使用,进行应用中的交互 package com.example.intent; import android.app.Activity; import android ...
- Android 通过 Intent 传递类对象或list对象
(转:http://www.cnblogs.com/shaocm/archive/2013/01/08/2851248.html) Android中Intent传递类对象提供了两种方式一种是 通过实现 ...
- Android中Intent传递对象的两种方法(Serializable,Parcelable)
今天要给大家讲一下Android中 Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是 Bundle.putP ...
- Android中Intent传值与Bundle传值的区别详解
Android中Intent传值与Bundle传值的区别详解 举个例子我现在要从A界面跳转到B界面或者C界面 这样的话 我就需要写2个Intent如果你还要涉及的传值的话 你的Intent就要写两 ...
- Xamarin Android提示内存溢出错误
Xamarin Android提示内存溢出错误 错误信息:java.lang.OutOfMemoryError, Consider increasing the value of $(JavaMaxi ...
随机推荐
- iOS 判断当前网络状态的三种方法
http://www.cocoachina.com/ios/20171103/21039.html 在项目中,为了好的用户体验,有些场景必须线判断网络状态,然后才能决定改干嘛.比如视频播放,需要线判断 ...
- latex 图片标题居中
1.有一个全局图片标题居中的方法: \usepackage[justification=centering]{caption} 2.如果排版时有的图标题想左对齐,有的想居中,前一个方法就不好了,这里可 ...
- Windows10 Build 18298 桌面显示计算机(此电脑)
- rem移动端适配方案
一. rem vs em 单位 定义 特点 rem font size of the root element 以根元素字体大小为基准 em font size of the element 以父元素 ...
- oracle事务的四个特性(ACID)
事务产生的背景 当在PL/SQL中同时操作多个SQL语句,比如通过DML语句添加.修改或删除数据时,如何确保数据库数据不会因为意外而倒置错误数据是一个非常重要的问题. 以仓库发料系统为例,如果某一张领 ...
- .Net批量插入数据
1. 一般我们普通数据插入是这样的: 现在我们写一个控制台程序用常规办法添加10000条数据. //以下是批量插入数据的办法 //连接字符串 string str = "Server=.;D ...
- 4.请介绍一下c++和Java的区别
1.指针 2.c++多重继承,Java只能继承一个父类,但是可以继承多个接口 3.数据类型及类,Java完全面向对象,所有函数和变量都必须是类的一部分.而c++允许将函数和变量定义为全局,Java取消 ...
- Python 基础知识----数据类型
一.Number 类型(数值类型) 二.String 类型 (字符串类型) 三.List 类型 (列表类型) 是一种常用的序列类型簇,List 用中括号 [ ] 表示,不同的元素(任意类型的值)之间以 ...
- hive数学函数
round 四舍五入 ceil向上 取整 floor向下取整 hive > select floor(45.8); ok 45
- Python:matplotlib绘制条形图
条形图,也称柱状图,看起来像直方图,但完是两码事.条形图根据不同的x值,为每个x指定一个高度y,画一个一定宽度的条形:而直方图是对数据集进行区间划分,为每个区间画条形. 将上面的代码稍微修改一 ...