- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有两个 Activity A 和 B。A 在应用程序启动时启动。我有一个从 A 启动的服务。
这是我在 Activity A 中的代码。
Button btnStart = (Button) findViewById(R.id.button1);
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startService(new Intent(getBaseContext(), Service_class.class));
}
});
这是我服务中的 onStartCommand 方法。
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
createNotification();
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
这是 createNotification 方法
private void createNotification() {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent nintent = new Intent();
nintent.setClass(this, TestActivity.class);
PendingIntent pin = PendingIntent.getActivity(getApplicationContext(),
0, nintent, 0);
String title = "KR Darsan";
String body = "This is a notification from darsh";
Notification n = new Notification(R.drawable.ic_launcher, body,
System.currentTimeMillis());
n.contentIntent = pin;
n.setLatestEventInfo(getApplicationContext(), title, body, pin);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(unique_id, n);
}
我正在挂起的 Intent 中设置 Activity B (TestActivity)。通知会根据需要显示,但是当我单击通知时, Activity 未启动。
我在 list 中声明了该服务。
<service android:name=".Service_class" />
还有什么我应该在 list 中声明的吗?可能是什么问题?
最佳答案
你是否在AndroidManifest.xml
中声明了TestActivity.class
?
关于android - 未决 Intent 在服务创建的通知中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12136519/
我知道未决 Intent 的概念,但标志令人困惑。 连android文档都很难看懂 有人可以通过示例提供未决 Intent 标志的解释,特别是 FLAG_ONE_SHOT 和 FLAG_NO_CREA
试图显示来自 json 的数据。 当我在控制台上运行我的函数时,它显示: Promise {} 和 [[PromiseState]]:“已完成” 但实际上并没有返回任何东西。 getJobs = as
我的代码是这样的,点击按钮我执行 Calendar calendar = Calendar.getInstance(); calendar.setTimeInMil
function f () { return new Promise(function (resolve, reject) { resolve(4); }) } fun
我有两个 Activity A 和 B。A 在应用程序启动时启动。我有一个从 A 启动的服务。 这是我在 Activity A 中的代码。 Button btnStart = (Button) fin
我正在开发一个应用程序,我想在其中设置自定义闹钟。但是在设置闹钟时间后没有任何反应。我正在分享我的代码。如果我的代码中缺少某些内容,请帮助和指导我。 在我的 MainActivity.java 中
我正在使用 fetch 来获取数据,但它一直将 promise 返回为待处理。我看过很多关于这个问题的帖子,并尝试了所有的可能性,但没有解决我的问题。我想知道为什么 fetch 简要地返回 promi
你好,我有以下在我的应用程序中显示通知的功能,但是我突然开始遇到一个问题,当我单击通知时它不会将我带到我在 .setContentIntent() 中指定的 Activity ,这是我的代码: @Ta
我正在创建一个数据处理程序,作为该过程的一部分,我需要下载一个文件,然后作为处理程序的一部分进行解析和使用。 我将对文件的请求包装在一个 promise 中,并从其他方法异步调用该方法 我已经包含了来
我想做的是通过intent传递数据, >创建者 intent = new Intent(this, AlarmReceiverActivity.class); intent.putExtra("id"
我正在使用 PingService.java 的代码 https://github.com/android/platform_development/blob/master/samples/train
我需要在用户靠近给定地点时通知他。我为此使用地理围栏 API。当我使用模拟位置在 Android 模拟器上测试应用程序时,一切正常。与模拟位置的真实设备相同。但是当我走路并且我的手机处于深度 slee
我有一个显示随机数的简单小部件。点击时它会刷新并显示另一个随机数。这是 AppWidgetProvider 的 onUpdate 方法的代码 public void onUpdate(Context
PendingIntent 中的一个新 PendingIntent 字段是 FLAG_IMMUTABLE。 在31中,必须指定MUTABLE或IMMUTABLE,否则不能创建PendingIntent
我是一名优秀的程序员,十分优秀!