开发者

Running two activities at the same time on the screen

I need help doing something that I am sure is simple, but I can't figure out how to do it. I 开发者_StackOverflow社区have a counter down and when it gets to the last 60 seconds, it calls a 'lastminute' counter activity. The plan is to overlap the last 60 seconds over the actual application. Here is the problem, how can I change the code to allow the two activities to start at the same time. I have tried this;

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

but this does not put both applications on the screen, what I want is DASHBOARD on the background and LASTMINUTE on top. LASTMINUTE is alreay a "transparency colour".

Thanks; Ramón


It won't work the way you're currently trying to do it. There can only be one visible activity at a time.

You should first start the dashboard Activity and from there you should start lastminute.

Edit --

Use a Bundle object.

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")


You need to implement the lastminute functionality in a dialog that you create and show in the onCreate method of your dashboard activity.

EDIT: To distinguish between which activity that starts the new activity, use 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
}


Try using android:theme="@android:style/Theme.Translucent.NoTitleBar in Activity attributes for LastMinute in AndroidManifest.xml. I hope it'll be productive.


I think using Android fragments will help u to show two separate activities in the context of another main activity. try reading this: http://developer.android.com/guide/components/fragments.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜