Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从我的应用程序中运行另一个应用程序,但在该应用程序关闭后继续执行?_Android_Android Intent_Wait_Background Foreground - Fatal编程技术网

Android 从我的应用程序中运行另一个应用程序,但在该应用程序关闭后继续执行?

Android 从我的应用程序中运行另一个应用程序,但在该应用程序关闭后继续执行?,android,android-intent,wait,background-foreground,Android,Android Intent,Wait,Background Foreground,好的,我有一个程序(prog1),它通过意图打开另一个程序(prog2)。我的目标是让prog1在prog2处于前景时不做任何事情。当prog2退出前台时,让prog1继续执行 Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { Intent LaunchIntent = new Intent(Intent.ACTION_MAIN);

好的,我有一个程序(prog1),它通过
意图打开另一个程序(prog2)。我的目标是让prog1在prog2处于前景时不做任何事情。当prog2退出前台时,让prog1继续执行

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
        Intent LaunchIntent = new Intent(Intent.ACTION_MAIN); 
        LaunchIntent = getPackageManager().getLaunchIntentForPackage("prog2");     
        startActivity(LaunchIntent);
    }}, 3000);  // 3 seconds
但我不知道接下来该怎么办


这有可能吗?是否有人可以提供关于从这里到哪里的指导?

一个粗略的猜测,但请尝试startActivityForResult()您是否尝试过覆盖暂停和恢复?当第二个应用程序打开时暂停进程,在关闭时继续。我不认为这可以保证工作正常。startActivityForResult()仅在从中调用结果的活动仍然可访问时才会返回结果。如果您启动一个新的应用程序,这将把您当前的活动发送到后台,在那里它将接受垃圾收集,如果它被gc’ed,则无法接收结果。避免这种情况的方法是以某种方式将其链接到您调用的应用程序(如服务绑定)。如果被调用的应用程序碰巧在关闭时发出系统广播,您可以在清单中注册一个侦听它的接收器。是的,startActivityForResult()不起作用,因为应用程序不返回结果。。。有办法监控广播吗?