I made very simple app. Basically I have activity A that starts activity B if button is pressed. So here's the code
openMapFAB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), MapActivity.class);
intent.putExtra("routeId", id);
startActivity(intent);
}
});
But here's the problem. activity B is very heavy (it basically open map (mapsforge) and do other heavy calculations). So when pressing buton my UI freezes about 4 seconds and then I get activity B opened. I would like to show some animation like circle progress bar or something like that. So is it possible to start activity not in the UI thread?
Here's what I tried so far
new Thread(new Runnable() {
@Override
public void run() {
while (progressStatus < 100) {
progressStatus += 25;
handler.post(new Runnable() {
@Override
public void run() {
//animation code
}
});
try {
Thread.sleep(1600);
if (progressStatus == 100){
Intent intent = new Intent(getActivity(), MapActivity.class);
intent.putExtra("routeId", id);
startActivity(intent);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
However this is not exactly what I need. Any solutions or suggestions?