完成AsyncTask时出错

时间:2016-05-25 23:01:26

标签: android

从用户收到图片后,将它们放入数组中,从main调用animate()方法,此方法包含Asynktask。我怎样才能完成这个AsyncTask? 这是我的代码:

@property (nonatomic, strong) MCSession *peerSession;

- (void)startSession {
    MCPeerID *peerId = [[MCPeerID alloc] initWithDisplayName:[[UIDevice currentDevice] name]];
    self.peerSession = [[MCSession alloc] initWithPeer:peerId];
    self.peerSession.delegate = self;

    MCAdvertiserAssistant *advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:@"myapp" discoveryInfo:nil session:self.peerSession];
    [advertiser start];
}

- (void)openBrowser {
    MCBrowserViewController *peerBrowser = [[MCBrowserViewController alloc] initWithServiceType:@"myapp" session:self.peerSession];
    peerBrowser.delegate = self;
    [self.appDelegate.mainViewController presentViewController:peerBrowser animated:TRUE completion:nil];
}

1 个答案:

答案 0 :(得分:0)

从您的代码中,我猜您想要的是定期更改您在ImageView中显示的图像。我建议您更改代码以使用Timer

private Timer mTimer;

private void startCarousel(){
    mTimer = new Timer();
    TimerTask timerTask = new TimerTask() {
        public void run() {
            // Your periodic task...
        }
    };

    mTimer.schedule(timerTask, 1000, 500);
}

private void stopCarousel(){
    if(mTimer != null){
        mTimer.cancel();
        mTimer.purge();
    }
}