2012-08-16 70 views
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" /> 
+0

该链接似乎被打破 – 2012-08-16 03:21:15

+0

不适用于它它的工作原理 – Peter 2012-08-16 10:57:14

回答

0

我想通了,我的问题,我需要从我的主要活动中拨打电话finish();,以便它再次不会重新启动我的其他活动已启动。

相关问题