0

So, kind of a noob situation, but today, out of curiosity, I tried to do something like:

new Activity().runOnUiThread( new Runnable{...})

mostly because i don't actually have access to any activities (working on a 3rd party library). I just have the applicationContext, which i don't think allows me to make that runOnUiThread call.

So i guess i'm kind of wondering if there is a way to somehow fake out a minimally-invasive activity just so i can run something on the UI thread (or do other things, like pop up dialog...etc.) ??

if not, does anyone know what's wrong with just making new Activity() ? ( i mean, aside from the fact that, yes, i will get a null pointer because i haven't set my base context since the onCreate for the activity never got called ). if possible, i would like to accept an answer that can provide a little more detail and more "context" (no pun intended)

4

2 回答 2

4
new Handler(context.getMainLooper()).post(new Runnable()
{
    @Override
    public void run()
    {
    }
});
于 2013-08-08T02:18:56.153 回答
1

Activity 由 Android 操作系统管理,并不打算以这种方式使用,这样做意味着违反 API 合同,所以不要指望它会正常运行。

如果要显示一些对话框,只需创建一个具有透明背景的 Activity,对用户来说,它与浮动在另一个屏幕上方的单个 Dialog 相同。

于 2013-08-08T02:27:41.423 回答