10

I'm writing an Android application and I would like to place a dialog or view over the home screen so that a user can enter text without jumping into my full application. I can't seem to get this to work. If I present a dialog (even in a transparent activity), my application launches.

If you don't know what I'm talking about, take a look at the Facebook widget. I want to replicate a similar behavior to the clicking on the "What's on your mind?" box.

Thanks for any help in advance!

-Brian

strange quark
  • 5,205
  • 7
  • 41
  • 53
  • "If I present a dialog (even in a transparent activity), my application launches." What does this mean to you? To me, an "application" is going to *have* to launch, otherwise your code will not run. – CommonsWare Apr 24 '10 at 17:16

4 Answers4

10

My problem was that the application always launched to display the dialog.

To solve this, I set the activity lauch mode to singleInstance in the manifest. Now it shows the dialog over the home screen!

strange quark
  • 5,205
  • 7
  • 41
  • 53
  • Altought it's working, it's makes bug in andoid 6, (yes, I saw it's an aold question, but google doent care...). You have to use 'documentLaunchMode' to prevent it to overide your own application in the "Recent Screens" (especially if you also use excludeFromRecents). – Remy Aug 04 '16 at 09:43
7

They are launching an activity, but they've set the activity's theme so it looks like a Dialog.

In your manifest, you have to add something like this under the <activity> tag: android:theme="@android:style/Theme.Dialog"

Al.
  • 2,285
  • 2
  • 22
  • 30
2

Thanks a lot, I tried with Theme.Dialog

  <activity android:name=".language"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Dialog">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>

But in my code, there is 2 different floating windows : my layout and the tile. Here is the following code:

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.app.Dialog; 

public class language extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       // setContentView(R.layout.main);
        Dialog dialog = new Dialog(this); 
        dialog.setContentView(R.layout.main); 
        dialog.setTitle("Raygional"); 
        dialog.show();

    }
}

PS : I know this should be a question rather than an answer

Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110
0

Use Service for that

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.getApplicationContext().startActivity(intent);

below is some code`

public class HomepopupDataService extends Service {

private static final String TAG = "HomepopupDataService";

@Override
public void onCreate() {
    Log.i(TAG, "Service onCreate");
}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    Log.i(TAG, "Service onStartCommand");

    CountDownTimer dlgCountDown;
    Log.e("---------------", "onHandleIntent");
    dlgCountDown = new CountDownTimer(10000, 1000) {
        public void onTick(long millisUntilFinished) {
            Log.e("---------------", "onHandleIntent++");
        }

        public void onFinish() {
            Intent i = new Intent(getApplicationContext(),
                    DialogActivity.class);

            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getApplicationContext().startActivity(i);
        }
    }.start();
    return super.onStartCommand(intent, flags, startId);
}

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    Log.i(TAG, "Service onBind");
    return null;
}

@Override
public void onDestroy() {
    Log.i(TAG, "Service onDestroy");
}

}
Michał Kutra
  • 1,202
  • 8
  • 21
jigar
  • 307
  • 2
  • 11