将Context传递给构造函数并将其保存为私有变量供内部使用是不好的做法吗?另一种选择是将Context作为参数传递给需要它的方法.
哪个更好?我有一种感觉,传递给构造函数可能会导致内存泄漏意外.
看来你必须在onActivityResult中调用super方法
super.onActivityResult(requestCode, resultCode, data);
Run Code Online (Sandbox Code Playgroud)
当我按下Activity上的后退按钮时,我从TTS收到此错误.显然,这是因为我没有调用shutdown(),但我是,请参阅下面的onDestroy().我制作了一个活动扩展的抽象TtsActivity类.我在所有子类中调用super.onDestroy().
12-05 18:04:05.268: ERROR/ActivityThread(30240): Activity com.mysite.myapp.ActivitySelectItGame has leaked ServiceConnection android.speech.tts.TextToSpeech$1@43e9b4a0 that was originally bound here
12-05 18:04:05.268: ERROR/ActivityThread(30240): android.app.ServiceConnectionLeaked: Activity com.mysite.myapp.ActivitySelectItGame has leaked ServiceConnection android.speech.tts.TextToSpeech$1@43e9b4a0 that was originally bound here
12-05 18:04:05.268: ERROR/ActivityThread(30240): at android.app.ActivityThread$PackageInfo$ServiceDispatcher.<init>(ActivityThread.java:1121)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at android.app.ActivityThread$PackageInfo.getServiceDispatcher(ActivityThread.java:1016)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at android.app.ContextImpl.bindService(ContextImpl.java:863)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:467)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:433)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at com.mysite.android.library.activity.ActivityTTS.onActivityResult(ActivityTTS.java:98)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at com.mysite.myapp.ActivityGame.onActivityResult(ActivityGame.java:445)
12-05 18:04:05.268: ERROR/ActivityThread(30240): at android.app.Activity.dispatchActivityResult(Activity.java:3890) …Run Code Online (Sandbox Code Playgroud) 我只是试图了解TypeScript,
说我有这样一个模块animals.ts:
export module Animals {
export interface Animal {
name(): void;
}
export class Elephant implements Animal {
constructor() {
}
public name() {
console.log("Elephant");
}
}
export class Horse implements Animal {
constructor() {
}
public name() {
console.log("Horse");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想在另一个文件中使用此模块animals_panel.ts:
import animals = require("animals")
module AnimalPanel {
var animal = new animals.Animals.Elephant();
animal.name();
}
Run Code Online (Sandbox Code Playgroud)
animals.Animals.Elephant(),我本来期望Animals.Elephant().我做错了什么或者这是正确的行为吗?import animals = require("animals")在AnimalPanel模块内导入(我尝试这样做时会出错)?在arrays.xml中
<string-array name="my_items">
<item>My item 1</item>
<item>My item 2</item>
<item>My item 3</item>
</string-array>
Run Code Online (Sandbox Code Playgroud)
在strings.xml中
<resources>
<string name="item1">My item 1</string>
<string name="item2">My item 2</string>
<string name="item3">My item 3</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
我想在strings.xml中引用数组"My item 1"中的字符串.我怎么做?
是否可以通过Intent将对象发送到Android服务而不实际绑定到服务?或者也许是服务访问对象的另一种方式......
我从客户端远程获取以下内容,因此我不知道他们正在使用什么硬件等.
java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
at android.view.Window$LocalWindowManager.removeView(Window.java:417)
at android.app.Dialog.dismissDialog(Dialog.java:279)
at android.app.Dialog.access$000(Dialog.java:72)
at android.app.Dialog$1.run(Dialog.java:108)
at android.app.Dialog.dismiss(Dialog.java:263)
at com..mysite.android.ActivityGame$1.onFinish(ActivityGame.java:154)
at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4203)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
Run Code Online (Sandbox Code Playgroud)
这是因为ProgressDialog而发生的
progressDialog = new ProgressDialog( this );
progressDialog.setMessage(getString(R.string.get_ready));
progressDialog.setCancelable(false);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMax(12);
progressDialog.show();
new CountDownTimer(3000, 250) {
@Override
public void onTick(long millisUntilFinished) {
//progressDialog.incrementProgressBy(1);
}
@Override
public void onFinish() {
progressDialog.dismiss(); //********* ERROR HAPPENS HERE *********
nextQuestion();
}
}.start();
Run Code Online (Sandbox Code Playgroud)
活动在清单中看起来像这样. …
我注意到了
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Run Code Online (Sandbox Code Playgroud)
只被召唤一次.我需要在每次显示菜单时调用它,因为我根据应用程序状态在菜单中添加/删除项目.
这可能吗?
我需要访问JUnit Test的Android上下文.
我尝试过使用MockContext并扩展AndroidTestCase,但每次我收到错误说(存根!)
我有两个文件夹,src和test(对于junit).当我导出时,测试文件夹被打包到带有JUnit的jar中,这是我不想要的.我去了项目的构建路径,试图在'导出顺序'中取消选择'test'文件夹,但它不允许我取消选择它.
然后我尝试使用*(所有)排除'soruces'选项卡中的文件夹,但是当我尝试导出时出现错误.
如何从导出中排除我的测试文件夹?