Android popup style activity which sits on top of any other apps

Posted by RenegadeAndy on Stack Overflow See other posts from Stack Overflow or by RenegadeAndy
Published on 2011-01-06T23:32:19Z Indexed on 2011/01/06 23:54 UTC
Read the original article Hit count: 354

Filed under:
|
|

What I want to create is a popup style application.

I have a service in the background - something arrives on the queue and i want an activity to start to inform the user - very very similar to the functionality of SMSPopup app.

So I have the code where something arrives on the queue and it calls my activity.

However for some reason the activity always shows on top of the originally started activity instead of just appearing on the main desktop of the android device.

As an example:

I have the main activity which is shown when the application is run

I have the service which checks queue

I have a popup activity.

When i start the main activity it starts the service - I can now close this.

I then have something on the queue and it creates the popup activity which launches the main activity with the popup on top of it :S How do I stop this and have it behave as i want...

The popup class is :



package com.andy.tabletsms.work;


import com.andy.tabletsms.tablet.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

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();
 }
}




and I call the activity from a broadcast receiver which checks the queue every 30 seconds or so :


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

      }

The layout is here : http://pastebin.com/F25u6wdM

© Stack Overflow or respective owner

Related posts about java

Related posts about android