Android 当应用程序使用Alarm Manager启动时,如何将附加内容传递给intent?

Android 当应用程序使用Alarm Manager启动时,如何将附加内容传递给intent?,android,android-intent,Android,Android Intent,在我正在开发的应用程序中,我有一个报警管理器,它将在特定时间启动应用程序。在这个过程中,我将传递一个字符串作为intent的一部分,如下所示 Intent LaunchIntent = context.getPackageManager().getLaunchIntentForPackage("Application Package Name"); String strName = "Preferences"; LaunchIntent.putExtra("STR

在我正在开发的应用程序中,我有一个报警管理器,它将在特定时间启动应用程序。在这个过程中,我将传递一个字符串作为intent的一部分,如下所示

Intent LaunchIntent = context.getPackageManager().getLaunchIntentForPackage("Application Package Name");
        String strName = "Preferences";
        LaunchIntent.putExtra("STRING_NAME", strName);
        context.startActivity(LaunchIntent);
它正在打开应用程序。但是在when i do
intent.getStringExtra(“STRING_NAME”)
中,在主屏幕的onCreate()方法中,传递的字符串值不会出现

在这个类中,我每40秒初始化一次alarm manager,如下onCreate方法所示:

private static void SetScheduleSync(Context context) {
        Intent downloader = new Intent(context, ScheduleSyncManager.class);

        PendingIntent recurringDownload = PendingIntent.getBroadcast(context, 1000, downloader, PendingIntent.FLAG_CANCEL_CURRENT);

        AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        int interval = 10000*4;
        manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, recurringDownload);
    }
在ScheduleSyncManager.class中,我编写了代码,通过将附加项作为pert of intent传递来打开应用程序。当应用程序打开时,我将检查特定目的中是否有任何额外数据

以下是ScheduleManagerDeclaration:

public class ScheduleSyncManager extends WakefulBroadcastReceiver {
    public Boolean IsCustomizingPresent = false;
    String strName = "Preferences";

    @Override
    public void onReceive(Context context, Intent intent) {

        Toast.makeText(context, "Sync in the background has Started", Toast.LENGTH_SHORT).show();
        performScheduleSync(context, intent);
    }

    public void performScheduleSync(Context context, Intent intent) {

        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.sap.rex.ui");
        launchIntent.putExtra("STRING_NAME", strName);
        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(launchIntent);
        }
在我发布下面的代码时,我正在Oncreate()方法中通过函数SetScheduleSync()调用ScheduleManager

请帮我做这个。有可能这样做吗

谢谢。

尝试以下方法:

LaunchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

注意:通常情况下,实例的首字母应小写,即不是LaunchIntent而是LaunchIntent

当然,我会尽力让你知道的。谢谢,我累了。但它仍然不是作为intent extras的一部分出现。可能是这样的:LaunchIntent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_CLEAR_TOP);不走运。没用。可以这样发送吗?如果仍然没有解决,您可以共享您的代码以便我们也可以测试它吗?