1
我構建了一個應用程序,該應用程序有一個活動,我想從點擊狀態通知圖標開始。我想要發生的是我的活動,我設置爲顯示一個對話框,顯示在設備上已經打開的任何應用程序的頂部。在沒有主應用程序的情況下啓動一個對話框
但現在發生的情況是,當單擊通知圖標時,對話框活動與其下面的應用程序主活動一起啓動,如下圖所示。
http://postimage.org/image/s40v1588b/
我怎樣才能啓動對話框,以便它顯示了在當前的應用程序在屏幕上,我的主要活動將不啓動?
主要活動:
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();
}
});
}
}
服務偵聽通知新聞界,並開始對話活動:
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);
}
}
清單:
<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" />
該鏈接似乎被打破 – 2012-08-16 03:21:15
不適用於它它的工作原理 – Peter 2012-08-16 10:57:14