【发布时间】:2011-01-06 23:32:19
【问题描述】:
我要创建的是弹出式应用程序。
我在后台有一项服务 - 队列中有东西到达,我希望启动一个活动来通知用户 - 非常类似于 SMSPopup 应用程序的功能。
所以我有一些代码到达队列并调用我的活动。
但是由于某种原因,Activity 总是显示在最初启动的 Activity 之上,而不是仅仅出现在 android 设备的主桌面上。
举个例子:
我有应用程序运行时显示的主要活动
我有检查队列的服务
我有一个弹出活动。
当我启动主要活动时,它会启动服务 - 我现在可以关闭它。
然后我在队列中有一些东西,它创建了弹出活动,该活动启动主要活动,并在其上弹出弹出窗口:S 我如何停止它并让它按我想要的方式运行...
弹出类是:
public class SMSPopup extends Activity implements OnClickListener{
public static String msg;
@Override
public void onCreate(Bundle bundle){
super.onCreate(bundle);
// Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
this.setContentView(R.layout.popup);
TextView tv = (TextView)findViewById(R.id.txtLbl);
Intent intent = getIntent();
if (intent != null){
Bundle bb = intent.getExtras();
if (bb != null){
msg = bb.getString("com.andy.tabletsms.message");
}
}
if(msg == null){
msg = "LOLOLOL";
}
tv.setText(msg);
Button b = (Button)findViewById(R.id.closeBtn);
b.setOnClickListener(this);
}
@Override
public void onClick(View v) {
this.finish();
}
}
我从广播接收器调用活动,该接收器每 30 秒左右检查一次队列:
if(main.msgs.size()>0){
Intent testActivityIntent = new Intent(context.getApplicationContext(), com.andy.tabletsms.work.SMSPopup.class);
testActivityIntent.putExtra("com.andy.tabletsms.message", main.msgs.get(0));
testActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(testActivityIntent);
}
【问题讨论】:
-
什么是'main'(如main.msgs.get(0)),它在哪里?
-
它是一个包含字符串的数组列表....与问题无关:)
-
所以你说 - “...启动主要活动并在其上弹出弹出窗口”。主要活动“真的”启动了吗?换句话说,当你按下 BACK 按钮时,弹出的活动消失了,你看到了后面的主要活动。还是弹出活动的背景与主要活动具有相同的标题栏,使其看起来像主要活动?
标签: java android android-layout