0

I got class calledA and my async class is written as a inner class of A. I got another class called B(Activity). Now im in B class. what i want is to call asyncTask of A.

I'm much confused with this question & if anyone can give me a correct answer he'll be a life saver. Hope u guys help me. Thanks.

codezoner
  • 1,054
  • 2
  • 13
  • 32

5 Answers5

7

Its so simple just Simply build an object of main class and than call the inner class like this

 OuterMainClass outer = new OuterMainClass();
       outer.new InnerAsyncClass(param)
         .execute();

this answer is too late to help you but hope it help others.

Thanks

Syeda Zunaira
  • 5,191
  • 3
  • 38
  • 70
1

you will need to move the async task from being annonymus class to be a normal class, instead of being inside class A.

Make a class that extends Asynctask and have two instances of that async task both in your activities.

meh
  • 22,090
  • 8
  • 48
  • 58
  • That's the way to go. If you need A's inner class AA inside of B, then you're doing something wrong. Just make A, B and C classes. – shkschneider Sep 12 '12 at 10:39
1

Making a separate Class of AsyncTask. and calling it in both activities is the answer.

user996428
  • 96
  • 1
  • 7
0

you can declare Async Task as public static inner class in Class A. and execute it from class B.

akashpandey
  • 177
  • 1
  • 11
0

I was in the same situation! Look at this answer...make on one service class to handle all your threading....perfect example here:

Good Example on GitHub WebServiceAsyncTask and WebServiceBackgroundActivity. VIA Android: How to run asynctask from different class file?

Community
  • 1
  • 1
Shehaaz
  • 753
  • 1
  • 7
  • 12