Android 在活动开始时获得通知/接收明确的意图
我正在开发一个应用程序,当用户选择的Android 在活动开始时获得通知/接收明确的意图,android,Android,我正在开发一个应用程序,当用户选择的活动启动时会收到通知。要使其起作用,最好的方法是为ACTION\u MAINexplicitIntents注册一个BroadcastReceiver,据我所知,这不起作用(因为这些Intent具有特定的目标)。另一种可能效率较低的方法是使用系统ActivityManager并轮询getRunningTask(),该方法返回当前所有正在运行的任务的列表。轮询可以由后台服务完成。通过监视此列表中的更改,我可以查看活动是否正在运行,以便我的应用程序可以得到通知。不利
活动启动时会收到通知。要使其起作用,最好的方法是为ACTION\u MAIN
explicitIntent
s注册一个BroadcastReceiver
,据我所知,这不起作用(因为这些Intent
具有特定的目标)。另一种可能效率较低的方法是使用系统ActivityManager
并轮询getRunningTask()
,该方法返回当前所有正在运行的任务的列表。轮询可以由后台服务完成。通过监视此列表中的更改,我可以查看活动是否正在运行,以便我的应用程序可以得到通知。不利的一面当然是民意调查。我还没有尝试过,但我认为最后一种方法可能会奏效
有谁知道一个更好的方法或建议,但不那么密集吗?为什么不能直接调用getParent()
这将出现在您的孩子的活动中
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent();
//Create this method in your Parent Activity
getParent().onChildCreated(this, intent);
}
public void onChildCreated(Activity child, Intent intent) {
/*
* Have fun (Edited to pass intent)
*/
}
这将出现在您的家长活动中
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent();
//Create this method in your Parent Activity
getParent().onChildCreated(this, intent);
}
public void onChildCreated(Activity child, Intent intent) {
/*
* Have fun (Edited to pass intent)
*/
}
我已经实施了第二种可能性。这完全取决于你的应用程序,你想多久进行一次民意调查