执行活动不显示在屏幕上的布局 [英] Executing activity without showing the layout on screen

查看:108
本文介绍了执行活动不显示在屏幕上的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜查不仅计算器,但另一个网站也一样,但我无法找到一个答案我的问题。我从现在开始学习Android的,我有一个关于活动的疑问。

I've searched not only stackoverflow, but another sites too, but I couldn't find an answer to my problem. I'm starting now to learn Android, and I have a doubt about activities.

我有一个创建了两个按钮的通知的MainActivity。一种是无用的现在和其他(发送按钮),将打开与一个EditText和一个按钮,警报将文本发送到另一个应用程序。

I have a MainActivity which creates a notification with two buttons. One is useless by now and the other (the Send button) will open an Alert with an EditText and a button to send the text to another app.

这是在code:

Intent mainActivityIntent = new Intent(MainActivity.this, NotificationActivity.class);
            Intent shareActivityIntent = new Intent(MainActivity.this, ShareActivity.class);
            PendingIntent mainActivityPIntent = PendingIntent.getActivity(MainActivity.this, 0, mainActivityIntent, 0);
            PendingIntent shareActivityPIntent = PendingIntent.getActivity(MainActivity.this, 0, shareActivityIntent, 0);

            Notification n = new Notification.InboxStyle 
                    (new Notification.Builder(MainActivity.this)
                    .setContentTitle(getString(R.string.text_notification))
                    .setContentText(getString(R.string.text_notification))
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(mainActivityPIntent)
                    .addAction(R.drawable.logo, "Botão", mainActivityPIntent)
                    .addAction(R.drawable.ic_launcher, "Share", shareActivityPIntent)
                            )
                    .build();

            n.flags |= Notification.FLAG_ONGOING_EVENT;

            NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            nm.notify(0, n);

正如你所看到的,发送按钮将打开另一个活动,其中有下面的code:

As you can see, the Send button will open another Activity, which has the code below:

AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Mensagem");
    alert.setMessage("Digite a mensagem");


    final EditText input = new EditText(this);
    alert.setView(input);

    alert.setPositiveButton("Enviar", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
      String value = input.getText().toString();
      Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_TEXT, value);
        startActivity(Intent.createChooser(i, "Enviar"));
        finishActivity(0);
      }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        return;
      }
    });

    alert.show();

本次活动负责打开,用户将输入的文本发送到其他应用程序的警报。

This activity is responsible for opening the alert where the user will input the text and send to another application.

的情况是,当我打电话的活动,它不仅显示了警告,但也开启了新的屏幕。例:通知是持久性的,所以它会一直显示在通知抽屉。如果我在另一个应用程序,我点击我的通知按钮,我想开只警报,但现在它打开警报,并在屏幕与我的活动布局。

The situation is that when I call the activity it not only shows the alert but also open a new "screen". Example: the notification is persistent, so it will be always showing on the notification drawer. If I'm on another app and I click the button on my notification, I want to open only the alert, but now it's opening the alert AND the screen with the layout for my activity.

有没有一种方法,只显示警告,而不显示活动?还是我用另一种方法来做到这一点?

Is there a way to show only the alert, without showing the activity? Or do I have to use another method to do this?

非常感谢你。

推荐答案

如果没有绝对需要一个警告对话框,可以使警报自己的活动,只是不能使用警报生成器。把按钮和textviews或者你需要,你会什么的。然后在清单中使用

If there's no absolute need for an alert dialog, you can make the alert its own activity and just not use the alert builder. Put buttons and textviews or whatever you need as you would. Then in the manifest use

<活动机器人:主题=@安卓风格/ Theme.Dialog>

这里 更多的是主题。希望这有助于

Here is more about themes. Hope this helps

这篇关于执行活动不显示在屏幕上的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆