1

in my app, i am switching one activity to another activity (Main.java to Feature_Screen.java). In the Feature_Screen(second activity) i am going to download large no of data and image to set in a grid view. so that i use Async Task for download it. although i use async task in second activity i get black screen while switching Main.java to Feature.java. i search in google but all the answers says use Async Task.

example coding:

public class Main extends TabActivity{

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabbar);
    .................
    intent = new Intent().setClass(this, Featured_Screen1.class);
    spec = tabHost.newTabSpec("home").setIndicator("",
            res.getDrawable(R.drawable.top_book_icon)).setContent(intent);
    tabHost.addTab(spec);
    ...........
}
}

In Feature_Screen1.java(Second.java):

public class Feature_Screen1 extends Activity{

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.feature);
    .................
      new Content_load().execute();
    ...........
}

 class Content_load extends AsyncTask<Void, Void, Void> 
   {
ProgressDialog dialog = new ProgressDialog(SignInPage.this);

protected void onPreExecute() { 
    dialog.setMessage("Please wait...");
    dialog.setCancelable(false);
    dialog.show();
}

protected void onPostExecute(Void unused) {
    dialog.dismiss();
}

protected Void doInBackground(Void... arg0) {
      ..........
  return null;
   }
  } 

}

my problem is how to avoid black screen while switching between activities? please help me.

M.A.Murali
  • 9,988
  • 36
  • 105
  • 182
  • Do you see the "Please wait" dialog at all? – Ted Hopp Nov 25 '11 at 14:53
  • 1
    yes but before getting "Please Wait" i get black screen after few seconds i get please wait.... – M.A.Murali Nov 25 '11 at 14:56
  • It looks like something hanging UI thread before AsyncTask get started. Post the dots code before new Content_load().execute(); in your Feature_Screen1.onCreate() may help other people find your problem. – yorkw Nov 25 '11 at 23:43
  • @murali_ma hi buddy.. Have you got the answer for your question.. because the same problem i am facing now... please if you got the answer post it.. it will be really helpul.. thanks – vinothp May 23 '12 at 17:05
  • @user1216003 hi buddy, No i do not get the answer for this question.my guess also is UI is hanging in the activity. – M.A.Murali May 23 '12 at 17:50
  • @murali_ma its alright.. anyway thanks for your reply.. If i found the answer i will let you know thanks... – vinothp May 23 '12 at 20:07
  • @user1216003, please let me know the answer if you found. thanks – M.A.Murali May 24 '12 at 05:38
  • Finally i found the answer, please see it below – vinothp May 30 '12 at 11:27

1 Answers1

0

Finally I found the answer for black screen problem..

Use AsyncTask like below, this worked for me, if you face any problems let me know

public class SyncroniseRecords extends AsyncTask<Void, Void, Void>
{  
    @Override
    protected void onPreExecute()
    {  
        super.onPreExecute();
        dialog.setMessage("Please wait...");
        dialog.setCancelable(false);
        dialog.show();

    } 
    @Override 
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
        // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
     }

    @Override 
    protected void onPostExecute(Void result)
    { 
           dialog.cancel();
    }
    @Override
    protected Void doInBackground(Void... params) {

        return null;
    }
} 

This will launch the Activity without any Black Screen. Using onPreExecute you can display the Progressbar.Once the process gets completed you can cancel it in OnPostExecute().

vinothp
  • 9,939
  • 19
  • 61
  • 103
  • Thanks you so much for your kind reply. i have one problem in android that is i need to convert wav file to mp3. do you know how to do it? please help me. i want to touch with you ever. – M.A.Murali May 30 '12 at 11:32
  • Have you solved that problem..For wav to mp3 please[Check this Link](https://github.com/halfninja/android-ffmpeg-x264) and [this](http://stackoverflow.com/questions/4725773/ffmpeg-on-android).It may help you.. – vinothp May 30 '12 at 12:13