我正在編寫一個Android應用程序,我希望在主屏幕上放置一個對話框或視圖,以便用戶可以輸入文本而無需跳到我的完整應用程序中。我似乎無法得到這個工作。如果我展示對話框(即使是透明的活動),我的應用程序也會啓動。他們如何做到這一點?主屏幕上的對話框
如果您不知道我在說什麼,請查看Facebook小部件。我想複製類似的行爲來點擊「你在想什麼?」框。
感謝您提前提供任何幫助!
-Brian
我正在編寫一個Android應用程序,我希望在主屏幕上放置一個對話框或視圖,以便用戶可以輸入文本而無需跳到我的完整應用程序中。我似乎無法得到這個工作。如果我展示對話框(即使是透明的活動),我的應用程序也會啓動。他們如何做到這一點?主屏幕上的對話框
如果您不知道我在說什麼,請查看Facebook小部件。我想複製類似的行爲來點擊「你在想什麼?」框。
感謝您提前提供任何幫助!
-Brian
我的問題是,應用程序始終啓動,以顯示該對話框。
爲了解決這個問題,我在清單中將activity lauch模式設置爲singleInstance
。現在它顯示主屏幕上的對話框!
Altought它正在工作,它使得類似於6的錯誤(是的,我看到這是一個古怪的問題,但谷歌沒有在意......)。您必須使用'documentLaunchMode'來防止它在「最近的屏幕」中覆蓋您自己的應用程序(特別是如果您還使用excludeFromRecents)。 – Remy 2016-08-04 09:43:38
他們是發起一項活動,但他們已經設置活動的主題,所以它看起來像一個對話框。
在你的清單,你必須添加這樣的事情<activity>
標籤下:android:theme="@android:style/Theme.Dialog"
謝謝,但我如何從我的應用程序小部件開始一個活動?我似乎無法找出未決的意圖。謝謝! – 2010-04-24 20:22:23
非常感謝,我試圖與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>
但在我的代碼中,有2不同的浮動窗口:我的佈局和瓷磚。這是下面的代碼:
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:我知道這應該是一個問題,而不是一個答案
那麼你爲什麼發佈它作爲答案? – 2010-04-25 10:38:36
它可能會讓其他想要在主屏幕上執行對話的人感興趣。 – 2010-04-25 11:13:50
使用服務爲
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.getApplicationContext().startActivity(intent);
下面
一些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");
}
}
「如果我提出一個對話框(即使是在一個透明的活動),我的應用程序啓動。」這對你意味着什麼?對我來說,一個「應用程序」將*啓動*,否則您的代碼將無法運行。 – CommonsWare 2010-04-24 17:16:17