В моем коде я начинаю Timertask, когда получено вещательное сообщение. Здесь я отобрал код двух классов. 1. Транслярный приемник. 2. XML -диапазон.
Мой вопрос: когда я звоню в Timertask, в запланированное время Timer Call, и я получаю все данные в XML Class. Like "Mservicelist"Но когда я хочу использовать этот массив каждый раз, когда он становится нулевым.
Я не уверен, где я делаю неправильно.
Если у любого тела есть идея, то это здорово.
public class MyWidgetIntentReceiver extends BroadcastReceiver {
public static int clickCount = 0;
private String msg[] = null;
private ParsingXML myXMLHandler;
private ArrayList<Stream> mServiceList = new ArrayList<Stream>();
private UrlTimerTask mUrlTimerTask = null;
private Timer mTimer = null;
private String rssFeed = "https;??.....";
@Override
public void onReceive(Context context, Intent intent) {
mUrlTimerTask = new UrlTimerTask();
mTimer = new Timer();
mTimer.scheduleAtFixedRate(mUrlTimerTask, 0, 120000); // (60*2*1000)
if (intent.getAction().equals(WidgetUtils.WIDGET_UPDATE_ACTION1)) {
Toast.makeText(context, "NEXT!!", Toast.LENGTH_SHORT).show();
updatePreviousWidgetListener(context);
}
}
private void updatePreviousWidgetListener(Context context) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
// updating view
remoteViews.setTextViewText(R.id.title, getNextTitle(context));
remoteViews.setTextViewText(R.id.desc, getDesc(context));
// re-registering for click listener
remoteViews.setOnClickPendingIntent(R.id.sync_button,
MyWidgetProvider.buildButtonPendingIntent(context));
// re-registering for click listener
remoteViews.setOnClickPendingIntent(R.id.next,
MyWidgetProvider.buildNextButtonPendingIntent(context));
MyWidgetProvider.pushWidgetUpdate(context.getApplicationContext(),
remoteViews);
}
private String getDesc(Context context) {
// some static jokes from xml
msg = context.getResources().getStringArray(R.array.news_headlines);
if (clickCount >= msg.length) {
clickCount = 0;
}
return msg[clickCount];
}
private String getNextTitle(Context context) {
if (mServiceList != null && mServiceList.size() > 0) {
return mServiceList.get(clickCount).getTitle().toString();
} else {
mStreamList = myXMLHandler.getItemsList();
Toast.makeText(context, "no data found", Toast.LENGTH_SHORT).show();
return "no data";
}
}
private class UrlTimerTask extends TimerTask {
@Override
public void run() {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
myXMLHandler = new ParsingXML();
xr.setContentHandler(myXMLHandler);
URL _url = new URL(rssFeed);
xr.parse(new InputSource(_url.openStream()));
mServiceList = myXMLHandler.getItemsList();
if (!mServiceList.isEmpty()) {
for (int i = 0; i < mServiceList.size(); i++) {
Log.d(TAG, mServiceList.get(i).getTitle());
}
}
} catch (ParserConfigurationException pce) {
Log.e("SAX XML", "sax parse error", pce);
} catch (SAXException se) {
Log.e("SAX XML", "sax error", se);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Тем не менее, у вас есть какой -либо вопрос о том, чтобы понять мой вопрос, пожалуйста, скажите мне, что я постараюсь понять мой запрос. Потому что я хочу ответить.
Краткое примечание: я хочу использовать данные анализа в класс приемника.
Спасибо,