簡體   English   中英

使用意圖在同一個類或新類中啟動方法

[英]Using intent to launch a method within the same class or new class

我猜我已經從他們的網站學到了如何在android studio中創建提名,並對它的運行方式有一個簡單的了解。 只需稍加修改= \\就可以進行更多復制和粘貼。 但是我沒有看到關於如何使用意圖在同一活動/類中啟動方法的任何信息。

根據我從android studio復制和粘貼的代碼:

public void showNotification()
{
    Intent emptyIntent = new Intent(this, JellyNotify.class);
    TaskStackBuilder backStack = TaskStackBuilder.create(this)
            .addNextIntent(emptyIntent)
            .addParentStack(JellyNotify.class);

    PendingIntent emptyPending = backStack.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification buildNoti = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.jelly)
            .setContentTitle("Feeling Jelly")
            .setContentText("Tap to launch Jar of Jelly")
            .setContentIntent(emptyPending)
            .build();

    NotificationManager manageNotification = (NotificationManager)
            getSystemService(Context.NOTIFICATION_SERVICE);

    manageNotification.notify(0,buildNoti);
}

我想我想說的是,當用戶單擊進行中的通知時,我正在嘗試啟動和活動或新意圖,甚至是我創建的類或新活動中的方法。 因此,過去一周我的大腦因搜尋而感到不快。 為了展示我的想法,我找到了一些網站,例如:

Android的er.blogspot

可點擊的通知-StackOverflow

嘗試這個,

如下更新您的意圖,

public void showNotification()
{
NotificationManager manageNotification = (NotificationManager)
        getSystemService(Context.NOTIFICATION_SERVICE);

Notification buildNoti = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.jelly)
        .setContentTitle("Feeling Jelly")
        .setContentText("Tap to launch Jar of Jelly")
        .setContentIntent(emptyPending)
        .build();

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,new Intent(this, Activity_you_needto_launch.class), PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

manageNotification.notify(0,buildNoti);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM