0

现在,我运行一个服务,我需要这个活动获取长按点击侦听器以获取其他活动或主屏幕中的坐标,然后启动一个活动以显示坐标。我应该怎么办?

4

3 回答 3

0
Intent dialogIntent = new Intent(getBaseContext(), myActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(dialogIntent);

Or From Solution Posted by MarcinGil

android.app.Service is descendant of android.app.Context so you can use startActivity directly. However since you start this outside any activity you need to set FLAG_ACTIVITY_NEW_TASK flag on the intent.

For example:

Intent i = new Intent();
i.setClass(this, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);       
where this is your service.
于 2013-07-31T10:00:08.837 回答
0

使用 Intent 启动新 Activity 并在捆绑中传递坐标值或作为 Intent extras

于 2013-07-31T09:58:19.587 回答
0

只需在您的服务中的 oncreate() 上添加以下代码

Intent intent = new Intent(Your_Context, Your_Class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
于 2013-07-31T11:05:38.950 回答