没有推出低于主应用程序对话框 [英] launching a dialog box without main application below
问题描述
我建了有我想从一个状态通知图标点击开始活动的应用程序。我希望发生的是我的活动,我设置为显示为一个对话框,显示了对任何应用程序是在设备上已经打开的顶部。
不过,现在情况是点击通知图标时,对话框活动是与它下面的应用主要活动一起推出,如图像波纹管似乎。
http://postimage.org/image/s40v1588b/
我如何启动对话框,以便它显示在屏幕上的当前应用程序,我的主要活动将不启动?
主要活动:
公共类mainActivity延伸活动{
公共NotificationManager mNotificationManager;
私人按钮启动; / **当第一次创建活动调用。 * /
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
mNotificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
启动=(按钮)findViewById(R.id.start);
start.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(查看视图){
意图myIntent =新意图(getApplicationContext(),servicetest.class);
startService(myIntent);
Log.d(开始,SMS);
Toast.makeText(SmseverywhereActivity.this,服务启动,
Toast.LENGTH_LONG).show();
} }); }}
服务侦听通知preSS和开始对话活动:
公共类servicetest延伸服务{
公共NotificationManager mNotificationManager;
公众意向dialogIntent; @覆盖
公众的IBinder onBind(意向意图){
// TODO自动生成方法存根
返回null;
}
@覆盖
公共无效的onCreate(){
super.onCreate();
Log.d(servicetest,的onCreate);
mNotificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
showNotification();
}
私人无效showNotification(){
通知不等于新的通知(R.drawable.ic_launcher,应用程序已启动,System.currentTimeMillis的());
意图myIntent =新意图(这一点,dialogactivity.class);
myIntent.putExtra(isFullScreen,真正的);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 的PendingIntent contentIntent = PendingIntent.getActivity(这一点,0,myIntent,Notification.FLAG_ONGOING_EVENT);
not.flags = Notification.FLAG_ONGOING_EVENT;
not.setLatestEventInfo(这一点,应用程序名称,应用程序说明,contentIntent);
mNotificationManager.notify(1,没有);
} }对话活动:
公共类dialogactivity延伸活动{
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow()。setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
的setContentView(R.layout.dialogtest); }
}
清单:
<应用
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:SmseverywhereActivityNAME =
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT; <活动
机器人:标签=@字符串/ APP_NAME
机器人:名字=NewText
机器人:主题=@安卓风格/ Theme.Dialog
机器人:launchMode =singleTask
机器人:screenOrientation =用户>
< /活性GT; <服务机器人:启用=真正的机器人:名字= />中servicetest。
我想通了,我的问题,我需要调用完成();
从我的主要活动,使它不是每一次我的其他活动启动时重新启动。
I built an application that has an activity that i want to start from the click of a status notification icon. What i want to happen is for my activity which i set to be shown as a dialog box to show up on top of whatever application is already open on the device.
But what happens now is that when the notification icon is clicked the dialog activity is launched along with the applications main activity underneath it, as seem in the image bellow.
http://postimage.org/image/s40v1588b/
How can i launch the dialog box so that it shows up over the current application on screen and my main activity isn't launched?
Main Activity:
public class mainActivity extends Activity {
public NotificationManager mNotificationManager;
private Button start;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
start = (Button) findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent myIntent = new Intent(getApplicationContext(), servicetest.class);
startService(myIntent);
Log.d("start","sms");
Toast.makeText(SmseverywhereActivity.this, "Service Started",
Toast.LENGTH_LONG).show();
}
});
}
}
Service that listens for notification press and starts dialog activity:
public class servicetest extends Service{
public NotificationManager mNotificationManager;
public Intent dialogIntent;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
super.onCreate();
Log.d("servicetest","onCreate");
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
showNotification();
}
private void showNotification(){
Notification not = new Notification(R.drawable.ic_launcher, "Application started", System.currentTimeMillis());
Intent myIntent = new Intent(this, dialogactivity.class);
myIntent.putExtra("isFullScreen", true);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, myIntent, Notification.FLAG_ONGOING_EVENT);
not.flags = Notification.FLAG_ONGOING_EVENT;
not.setLatestEventInfo(this, "Application Name", "Application Description", contentIntent);
mNotificationManager.notify(1, not);
}
}
Dialog activity:
public class dialogactivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.dialogtest);
}
}
manifest:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".SmseverywhereActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name="NewText"
android:theme="@android:style/Theme.Dialog"
android:launchMode="singleTask"
android:screenOrientation="user">
</activity>
<service android:enabled="true" android:name=".servicetest" />
I figured out my problem, I needed to call finish();
from my main activity so that it wasn't relaunched again every time my other activities were launched.
这篇关于没有推出低于主应用程序对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!