Start activity in doInBackground method

前端 未结 2 1149
忘掉有多难
忘掉有多难 2021-01-25 23:47

In below code i download json from internet and want to show in list. if list is empty go to another activity but other activity not start. no error but no start activity. thank

2条回答
  •  日久生厌
    2021-01-26 00:22

    This gets tricky. Some things to watch out for:

     Intent i = new Intent(getApplicationContext(), login.class);
    

    Make sure that the login class's type is in the manifest. Usually you reference the class by the class's name, not the instantiated variable. Honestly, it shouldn't make a difference but it's worth trying.

    Sometimes you get weird side-effects using different contexts. I think startActivity is one that's pretty sensitive to this. You can try AllNotes.this to get the running activity's context. There's a slim chance that this needs to be run on the UI thread, so you can try runOnUiThread() if that doesn't work.

提交回复
热议问题