Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle a silent SEND intent with a headless activity

Tags:

java

android

Just as the user who asked this: How does the default browser on Android send "SEND" intents?, I want my Android app to process a silent send. I implemented the proposed solution, a headless activity that never calls setContentView():

public class IntentMgrAct extends Activity {
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // setContentView explicitally ommited
       Toast.makeText(getApplicationContext(), "Message sent", Toast.LENGTH_LONG).show();
   }
}

When other apps send the intent to my "dumb" activity, it shows up behind the toast, but all I want is the toast. I tried to hide the headless activity with finish() after Toast.makeText and does the trick, but there is a noticeable flicker. How can I prevent the the activity from showing up?

like image 313
Jose_GD Avatar asked Jul 22 '11 21:07

Jose_GD


1 Answers

You need to add android:theme="@android:style/Theme.NoDisplay" to your <activity> element in the manifest.

like image 76
CommonsWare Avatar answered Sep 25 '22 22:09

CommonsWare