在方法的开头显示一个toast

时间:2017-09-04 10:55:02

标签: android methods show toast

问题很简单 我想在方法的开头显示一个(消息)吐司来进行等待

private void PartitionShow () {Toast.makeText (getApplicationContext (), "wait processing ...", Toast.LENGTH_LONG) .show ();// the code of my method// ...}

只有此消息才出现在我的方法代码的末尾

一个有效的解决方案是将代码放在一个类中:

private class DownloadFilesTask extends AsyncTask <String, Integer, String> {}

并管理吐司:

protected void onProgressUpdate (Integer ... progress) {}

有兴趣的人请参阅sample code

只有在我的代码中我才创建对象,并且将它放在另一个独立的线程中会变得很沉重和缓慢

感谢那些能找到更简单解决方案的人吗?

1 个答案:

答案 0 :(得分:0)

据我了解。

private void PartitionShow () {Toast.makeText (getApplicationContext (), "wait processing ...", Toast.LENGTH_LONG) .show ();// the code of my method// ...}
//// the code of my method//

将执行一些繁重的任务,如编写文件或批量数据存储或一些繁重的主线程操作。所以你可能会遇到一些小故障。你可以做两件事介绍新的AsyncTask或使用Handler进行线程操作。