它无法在应用程序中显示Toast,其他人也可以

时间:2015-05-07 10:00:04

标签: android toast

runOnUiThread(new Runnable() {
    @Override
    public void run() {
        Toast.makeText(PhotoListActivity.this, "ok", Toast.LENGTH_SHORT).show();
        LogUtils.printDebug("123", "ok");
    }
});

日志LogUtils.printDebug("123", "ok")有效,但Toast未显示。

3 个答案:

答案 0 :(得分:1)

尝试将PhotoListActivity.this更改为getAplicationContext()

答案 1 :(得分:0)

要么尝试这个..
PhotoListActivity.this.runOnUiThread(new Runnable() {
@Override
 .....
});

或者在getAplicationContext()

中使用此...。PhotoListActivity.this代替makeText()

答案 2 :(得分:0)

试试这个。唯一的问题是你给了Toast Short time

 void PDFToImage(MemoryStream inputMS, int dpi)
    {
        GhostscriptRasterizer rasterizer = null;
        GhostscriptVersionInfo version = new GhostscriptVersionInfo(
                                                                new Version(0, 0, 0), @"C:\PathToDll\gsdll32.dll", 
                                                                string.Empty, GhostscriptLicense.GPL);

        using (rasterizer = new GhostscriptRasterizer())
        {
            rasterizer.Open(inputMS, version, false);

            for (int i = 1; i <= rasterizer.PageCount; i++)
            {

                using (MemoryStream ms = new MemoryStream())
                {
                    DrawImage img = rasterizer.GetPage(dpi, dpi, i);
                    img.Save(ms, ImageFormat.Jpeg);
                    ms.Close();

                    AspImage newPage = new AspImage();
                    newPage.ImageUrl = "data:image/png;base64," + Convert.ToBase64String((byte[])ms.ToArray());

                    Document1Image.Controls.Add(newPage);
                }

            }

            rasterizer.Close();
        }
    }