相关疑难解决方法(0)

Android:如何从通知中恢复应用程序?

我正在尝试将我的通知编程为RESUME我的应用程序,而不是简单地启动我的应用程序的新实例...我基本上是在寻找它做同样的事情,因为长按主页按钮并恢复应用程序从那里.

这是我目前正在做的事情:

void notifyme(String string){

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager)
                                                getSystemService(ns);

    int icon = R.drawable.notification_icon;        // icon from resources
    CharSequence tickerText = string + " Program Running...";     // ticker-text
    long when = System.currentTimeMillis();         // notification time
    Context context = getApplicationContext();      // application Context
    CharSequence contentTitle = *********;  // expanded message title
    CharSequence contentText = string + " Program Running...";//expanded msg text

    Intent notificationIntent = new Intent(this, Main.class);
    PendingIntent contentIntent = PendingIntent.getActivity(
                                                this, 0, notificationIntent, 0);

    // the …
Run Code Online (Sandbox Code Playgroud)

android

14
推荐指数
1
解决办法
1万
查看次数

打开通知后,片段不会更新

我正在构建一个聊天应用程序,我有一个关于我的片段的问题,其中包含所有聊天的列表视图.

当用户收到消息时,聊天列表会更新(显示每个聊天的最后一条消息)(图像1).

当聊天不可见并且在该聊天中收到消息时,用户将收到通知(图2)

此时问题就出现了.当用户点击通知时,聊天列表视图似乎已被破坏.当用户在点击通知后收到另一条消息时,他/她的手机将振动,但聊天列表视图不会更改/更新.

单击通知后,其他视图可以正常工作.

下面是一段处理listview更新的代码.

    protected PacketListener packetListener = new PacketListener() {

    @Override
    public void processPacket(Packet packet) {
        final Message message = (Message) packet;

        if (message.getBody() != null) {
            final String fromName = StringUtils.parseName(message.getFrom());

            runOnUiThread(new Runnable(){

                @Override
                public void run() {

                    Boolean seen = false;
                    if(ChatFragment.currentChat != null && ChatFragment.currentChat.getContact().getUsername().equals(fromName) && VisibilityHelper.appIsVisible() && VisibilityHelper.fragmentIsVisible(ChatFragment.fragmentClassName)) {
                        seen = true;
                    }

                    Long chat_id = chatsDataSource.getChatByContactId(contactsDataSource.getContactByUsername(fromName).getId()).getId();
                    ChatMessage newChatMessage = chatMessagesDataSource.insertChatMessage(chat_id, ConstantHelper.CHAT_MESSAGES_TYPE_RECEIVED, seen, DateHelper.getDatetime(), message.getBody());

                    Log.d("DEBUG", VisibilityHelper.sCurrentFragmentClassName);
                    if(VisibilityHelper.appIsVisible() && …
Run Code Online (Sandbox Code Playgroud)

java android android-notifications android-fragments

5
推荐指数
1
解决办法
904
查看次数