我有一个Downloader服务,可以加载从我的数据库运行的下载列表.
然后它创建一个ASyncTask,它将在后台线程中运行下载.
这一切都运行得很好,但问题是我目前没有办法告诉服务该下载器已经完成.我不知何故必须从ASyncTask的onPostExecute函数(在UIThread上运行)发送一条消息.
我不能简单地远程关闭服务,因为当ASyncTask完成时,服务有一些工作要做.
我已经考虑过从服务中注册一个监听器并在onPostExecute中调用它,但我认为这会导致在Task完成之前关闭服务或一些threadlocking问题等问题.
如何从ASyncTask向我的Downloader服务发送消息(如广播意图)?
编辑
这里有一些代码让你对我正在做的事感到困惑.
DownloadService.java(重要位):
public class DownloadService extends Service implements OnProgressListener {
/** The Downloads. */
private List<Download> mDownloads = new ArrayList<Download>(10);
private DownloadTask mDownloadTask;
/** The Intent receiver that handles broadcasts. */
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent) {
DebugLog.i(TAG, "onRecieve" +intent.toString());
handleCommand(intent);
}
};
/* (non-Javadoc)
* @see android.app.Service#onCreate()
*/
@Override
public void onCreate() {
DebugLog.i(TAG, "onCreate");
mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
IntentFilter commandFilter = …Run Code Online (Sandbox Code Playgroud) 我有一套活动A,B,C.
用户可以进入A-> B-> C-> B-> C-> B. 我不希望B和C像这样重复.是否有任何意图标志我可以设置为限制为A-> B-> C,以便用户不必多次按后退按钮?
谢谢
我想从我的应用程序Activity中启动Contacts应用程序.我无法理解如何做到这一点.
Button contact = (Button) findViewById(R.id.contact);
contact.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i4 = new Intent();
i4.setAction(Intent.ACTION_VIEW);
i4.addCategory(Intent.CATEGORY_DEFAULT);
i4.setType("vnd.android.cursor.dir/phone");
startActivity(i4);
}
});
Run Code Online (Sandbox Code Playgroud)
错误:
我想启动手机库存日历应用程序,并使用该应用程序查看单个日历事件.有谁知道正确的Intent选项是做什么的?
我的Android应用程序有一个不活动超时.在超时时,我将用户返回到"登录"屏幕,该屏幕(始终)位于后台堆栈中.我的SignIn类已android:launchMode="singleTop"设置,因此总是重用在backstack中运行的实例.
我在超时时开始这个意图:
Intent inactivityTimeout = new Intent(this, SignIn.class);
inactivityTimeout.putExtra(INTENT_EXTRA_INACTIVITY_TIMEOUT, true);
int flags = inactivityTimeout.getFlags();
flags = flags|FLAG_FROM_BACKGROUND|Intent.FLAG_ACTIVITY_CLEAR_TOP;
inactivityTimeout.setFlags(flags);
Run Code Online (Sandbox Code Playgroud)
当SignIn屏幕启动时,它会检查INTENT_EXTRA_INACTIVITY_TIMEOUTIntent extra.如果找到,则显示"您已签名"对话框.这一切都正常.
现在我将解决这个问题:由于它基于一个计时器,无论我的应用程序是在前台还是后台,都可以触发此Intent.这是理想的,因为我不希望应用程序无限期地保持登录,因为它在后台.
但是,当应用程序在后台并且计时器到期时,将触发此inactivetivityTimeout Intent并将应用程序带回前台.这不是紧急提醒用户,现在他们已经超时,所以我宁愿在后台应用停留,以便不中断当前操作.
我尝试将FLAG_FROM_BACKGROUND标志添加到我的Intent,但应用程序仍然被带到前台.我不确定还有什么可以尝试,或者这是我应该在我的Intent或我的接收活动中解决的问题.
任何人都可以建议在我的Intent(或响应活动中)实现此方法吗?或者我在这里遗漏了一些概念?谢谢!
我正试图从一个程序中启动Android网络共享设置菜单,但它是其名称中包含斜杠的半隐藏菜单之一(com.android.settings/.tether.Tether),我不知道是什么我应该把它称为.这是我到目前为止所尝试的:
Intent intent = new Intent();
intent.setClassName("com.android.settings", "com.android.settings/.tether.Tether");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
我还尝试了setClassName行中的"com.android.settings /"
然而,无论哪种方式,它说它找不到类:
I/ActivityManager(51):启动活动:Intent {act = android.intent.action.MAIN cmp = com.android.settings/com.android.settings/.tether.Tether} D/AndroidRuntime(254):关闭VM W/dalvikvm(254):threadid = 3:线程退出,未捕获异常(group = 0x4001b188)E/AndroidRuntime(254):未捕获处理程序:由于未捕获异常导致主线程退出E/AndroidRuntime(254):java.lang.RuntimeException :无法启动活动ComponentInfo {com.zzzz.launcher/com.zzzz.launcher.Launcher}:> android.content.ActivityNotFoundException:无法找到显式活动类> {com.android.settings/com.android.settings /. tether.Tether}; 你有没有在AndroidManifest.xml中声明这个活动?
我的清单文件中列出了以下活动:
<activity android:name="com.android.settings/.tether.Tether" />
Run Code Online (Sandbox Code Playgroud)
(而且我也尝试用反斜杠逃避斜线,那里)
似乎没有任何关联的Settings.*值与之关联,因此通常的启动方式如下所示,不起作用:
startActivity(new Intent(Settings.ACTION_TETHER_SETTINGS));
Run Code Online (Sandbox Code Playgroud)
...但即便如此,我仍然想学习如何使用它的类名启动它,因为其他类的名称中包含斜杠(例如com.android.settings./proxySelector)我想以类似的方式发射.
干杯,
保罗
(进一步的堆栈跟踪:)
I/ActivityManager(59):开始活动:Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10200000 cmp = com.zzzz.launcher/.ProxySet bnds = [163,240] [237,319]} I/ActivityManager(59):启动proc com.zzzz.launcher for activity com.zzzz.launcher/.ProxySet:pid = 397 uid = 10040 gids = {1015} I/ActivityManager(59):启动活动: Intent {cmp = com.android.settings/.ProxySelector} D/AndroidRuntime(397):关闭VM …
确定活动1在gridVideoView中显示来自SD卡的视频缩略图.我希望能够点击并将数据传递到活动2并播放这些视频.我买的这本书只告诉我如何用字符串做这个.我怎么能这样做,所以当我点击活动1中的视频时,它会被传递并可以在活动2中播放?如果你想要我会发布的代码.
Intent intent = new Intent(getBaseContext(), Editor.class);
intent.putExtra("mnt/sdcard-ext", _ID);
startActivity(intent);
private VideoView video;
private MediaController ctlr;
File clip=new File(Environment.getExternalStorageDirectory(),
"mnt/sdcard-ext");
if (clip.exists()) {
video=(VideoView)findViewById(R.id.video);
video.setVideoPath(clip.getAbsolutePath());
ctlr=new MediaController(this);
ctlr.setMediaPlayer(video);
video.setMediaController(ctlr);
video.requestFocus();
video.start();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我如何在VideoView中引用意图?
我正在尝试更改textview的textview属性,如下所示:

在单独的Activity中,如下所示:

我尝试用捆绑包来做这件事,但我无法让它工作.这就是我的BookActivity的样子:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.book_activity);
//this is where the size property comes in
Integer size = getIntent().getExtras().getInt("SGRkey");
TextView test2 = (TextView) findViewById(R.id.booktext);
test2.setTextSize(size);
Spinner spinner = (Spinner) findViewById(R.id.kapitelspinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.kapitel_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Toast.makeText(parent.getContext(),
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
final String[] theporn = getResources().getStringArray(R.array.allkapitel);
TextView text = (TextView) findViewById(R.id.booktext);
text.setText(theporn[pos]);
}
public void onNothingSelected(AdapterView …Run Code Online (Sandbox Code Playgroud) 现在,我正在通过以下调用启动Google地图应用程序:
String geoAddress = "maps.google.com/maps?q=";
geoAddress += LatLong[0] + "," + LatLong[1];
Intent i = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(geoAddress));
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
这将打开标记并将其放置在地图上的指定位置.我有两个问题:
1)如何放置多个具有经度/纬度的标记?
2)如何将地图应用程序启动到其他模式(地形/卫星/等)?
谢谢!
我有一个"欢迎"屏幕,可以下载警报应该关闭的时间,但每次用户登陆屏幕时都会设置一个新的警报
这当然会导致多个警报
有什么方法可以检测出今天是否已经设定了?
感谢您的帮助
安迪
java android alarmmanager android-intent android-pendingintent
android ×10
android-intent ×10
java ×3
alarmmanager ×1
background ×1
calendar ×1
events ×1
google-maps ×1
resources ×1
service ×1
textview ×1
timeout ×1
video ×1