我正在開發一個基于 android 的帶類別的筆記應用程序。我應該在主屏幕上創建筆記快捷方式。當用戶點擊快捷方式時,相關活動應該打開,具體數據應該在編輯文本中設置,即它的標題和描述。我無法理解這樣做的邏輯。我嘗試了我想到的所有可能的解決方案。我在快捷方式意圖中傳遞了 Id of note,但是當它從快捷方式啟動時,字段仍然是空的。這是我創建快捷方式的代碼片段:創建快捷方式的函數: private void createShortcutOfActivity() { Intent shortcutIntent = new Intent(getApplicationContext(), TextNotes.class); shortcutIntent.setAction(Intent.ACTION_MAIN); Intent addIntent = new Intent(); addIntent .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, editTitle.getText().toString()); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); addIntent.putExtra("duplicate", false); //may it's already there so don't duplicate getApplicationContext().sendBroadcast(addIntent); }當用戶單擊創建快捷方式的選項時調用此函數。在 Menifest 使用權限中:<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />還在非啟動活動中添加意圖過濾器和導出屬性:<activity android:name=".TextNotes" android:exported="true"> <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>我還嘗試在函數的快捷意圖中使用此 id,但結果沒有變化。shortcutIntent.putExtra("key_primary",Id);我想在使用快捷方式打開時保留數據。例如,對于不同的筆記快捷方式,應該在字段中設置 rspected 數據,就像在 whatsapp 中一樣,可以創建不同聯系人的聊天快捷方式。但不幸的是,我無法理解應該怎么做,因為每次我使用快捷方式打開時,它的字段都會變空。從快捷方式啟動時我應該在哪里傳遞 id 以及如何設置數據。
通過活動快捷方式啟動時如何在字段中設置數據庫中的特定數據?
12345678_0001
2022-12-15 17:11:41