在屏幕上同时运行两个活动

时间:2011-07-14 11:39:32

标签: android android-activity

我需要帮助做一些我确信很简单的事情,但我无法弄明白该怎么做。我有一个计数器,当它到达最后60秒时,它会调用'lastminute'计数器活动。计划是在实际应用程序上重叠最后60秒。 这是问题所在,如何更改代码以允许两个活动同时启动。 我试过这个;

    public void onFinish() {
     startActivity(new Intent ("eu.merso.phoneapp.LASTMINUTE"));
     startActivity(new Intent ("eu.merso.phoneapp.DASHBOARD"));
     onDestroy();
 }

但这并没有将两个应用程序都放在屏幕上,我想要的是背景上的DASHBOARD和顶部的LASTMINUTE。 LASTMINUTE是一种“透明色”。

感谢; 拉蒙

4 个答案:

答案 0 :(得分:2)

它无法按照您目前的方式进行操作。一次只能有一个可见的活动。

您应首先启动仪表板活动,然后从那里开始最后一分钟。

编辑 -

使用Bundle对象。

Bundle bundle = new Bundle();

// Use 0 when the activity is called by the button and 
// 1 when it is called by the timer.
bundle.putInt("event_src", 0);
intentObject.putExtras(bundle);

// In your new activity you can then check whether to display
// the countdown or not
Int eventSrc = getIntent().getExtras().getInt("event_src")

答案 1 :(得分:1)

您需要在您创建的对话框中实现lastminute功能,并在仪表板活动的onCreate方法中显示。

编辑: 要区分开始新活动的活动,请使用intent extras:

//in your calling activity    
Intent i = new Intent(A.this, B.class);
i.putExtra("from Activity", A.class.getSimpleName());
startActivity(i);   


//in your receiving activity
String from = getIntent().getStringExtra();

if(from.equals(A.class.getSimpleName())){
//do something
}
else if(from.equals(C.class.getSimpleName())){
//do something
}

答案 2 :(得分:0)

尝试在AndroidManifest.xml中的LastMinute的Activity属性中使用android:theme="@android:style/Theme.Translucent.NoTitleBar。我希望它会很有效率。

答案 3 :(得分:0)

我认为使用Android片段将有助于您在另一个主要活动的上下文中显示两个单独的活动。 试试这个: http://developer.android.com/guide/components/fragments.html

相关问题