将正在运行的Android应用程序带到前台

时间:2015-03-06 17:04:18

标签: android android-activity broadcastreceiver

我正在设计一个测试工具,需要启动另一个应用程序,然后将我正在处理的活动恢复到前台。 我一直试图用接收器来解决这个问题,但到目前为止还没有运气。 任何建议都将非常感激。

1 个答案:

答案 0 :(得分:2)

如果你不想做任何特别的事情,那就不仅仅是 添加一个帖子作业(有一些延迟)到你当前的处理程序并发送一个Intent来启动你的活动,标志带到前台。

澄清的例子:

    /*
    * Your code to launch the 3rd party app
     */
    Handler handler=new Handler();
    handler.postDelayed(new Runnable(){
        public void run() {
            Intent openMe = new Intent(getApplicationContext(), MyActivity.class);
            openMe.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); //experiment with the flags
            startActivity(openMe);
        }}, 3000);

正如文件所述,也许你应该使用FLAG_ACTIVITY_REORDER_TO_FRONT

您还可以将信息存储在Intent内部,以便稍后检索并重新构建屏幕。

示例:

intent.putExtra("someStringAsIdentifier", someInformationObject);

你在onCreate中的新活动:

Intent i = getIntent();
Bundle extras = i.getExtras();
if(extras != null){
    informationObject = extras.getExtra("someStringAsIdentifier");
}

有关详细信息,请参阅Intent的文档。 :)

相关问题