我已经创建了IntentService类和执行asyncTask但onPreExecute()在此代码行调用时获得异常pDialog.show();
AsyncHandlerService类---
public class AsyncHandlerService extends IntentService{
ProgressDialog pDialog;
HttpPost post;
HttpResponse response;
Context ctx;
public AsyncHandlerService() {
super("AsyncHandlerService");
ctx = this;
}
@Override
protected void onHandleIntent(Intent intent) {
new LoadDeviceInfo().execute();
}
class LoadDeviceInfo extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ctx);
pDialog.setMessage("Updating device info...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show(); //Exception here..
}
protected String doInBackground(String... args) {
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
Run Code Online (Sandbox Code Playgroud)
更新:
我 …
android android-service android-asynctask android-intentservice
我有两个意向服务- IntentServiceA和IntentServiceB
它们具有以下类定义:
public class FirstService extends IntentService {
public FirstService() {
super("first_service");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("chi6rag", "first starts");
for (long i = 0l; i < 10000000l; i++) {
if (i == 0l) Log.d("chi6rag", "first started");
}
Log.d("chi6rag", "first ends");
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class SecondService extends IntentService {
public SecondService() {
super("second_service");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("chi6rag", "second starts");
for (long i = 0l; i < 10000000l; i++) {
if …Run Code Online (Sandbox Code Playgroud) JobIntentService每当有推送通知进入时,我都会启动该服务,以通知服务获取更多数据。当应用程序处于前台时,一切都会正常进行。
当应用程序在后台运行并且有多个推送通知进入时,该意图被排队,并且它多次执行相同的意图,这给服务器带来了不必要的压力,因为对服务器的第一次调用将获得它需要的所有信息,从而使另一个推送通知中不必要的排队意图。
是否有要取消或不向队列添加相同意图的方法,还是有其他方法可以防止对服务器的额外调用?
android intentservice android-intentservice jobintentservice
我想创建一个类似于这个的服务(从这里引用),以便在Android中异步下载多个文件.
public static class DownloadingService extends IntentService {
public static String PROGRESS_UPDATE_ACTION = DownloadingService.class
.getName() + ".newDownloadTask";
private ExecutorService mExec;
private CompletionService<NoResultType> mEcs;
private LocalBroadcastManager mBroadcastManager;
private List<DownloadTask> mTasks;
public DownloadingService() {
super("DownloadingService");
mExec = Executors.newFixedThreadPool( 3 ); // The reason to use multiple thread is to download files asynchronously.
mEcs = new ExecutorCompletionService<NoResultType>(mExec);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
protected void onHandleIntent(Intent intent) {
while(true)
{ …Run Code Online (Sandbox Code Playgroud) java multithreading android android-download-manager android-intentservice
我正在尝试在后台解压缩一些文件,所以我在google的教程中使用IntentService.我的服务类在AndroidManifest中声明如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.osmdroid">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:configChanges="orientation|screenSize|keyboardHidden"
android:hardwareAccelerated="true"
android:icon="@drawable/ecn_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MapActivity"
android:icon="@drawable/ecn_icon"
android:label="test" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings">
</activity>
<service
android:name=".UnZipService"
android:exported="false"/>
</application>
Run Code Online (Sandbox Code Playgroud)
在活动中,我有
IntentFilter intentFilter = new IntentFilter(DownloadManager
.ACTION_DOWNLOAD_COMPLETE);
receiverDownloadComplete = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long reference = intent.getLongExtra(DownloadManager
.EXTRA_DOWNLOAD_ID, -1);
if (myDownloadReference == reference) {
...
switch (status) {
case DownloadManager.STATUS_SUCCESSFUL:
Intent mServiceIntent = new Intent(context, UnZipService.class); …Run Code Online (Sandbox Code Playgroud) 我不确定它有什么不对!我在这里读到Intentservice本身就是它的子类Context.
public class GCMNotificationIntentService extends IntentService {
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
Context mainContext;
WriteFile writeFile;
public GCMNotificationIntentService() {
super("GcmIntentService");
mainContext = getApplicationContext();
writeFile = new WriteFile(mainContext);
}
// My rest of the code
}
Run Code Online (Sandbox Code Playgroud)
但是我的价值是空的mainContext.任何建议都是最受欢迎的.
android push-notification android-notifications android-intentservice
所以IntentService当我运行一次时,我运行正常.它需要一个图像处理它然后输出一系列RGB值.
但我现在需要它做的是多次运行批处理一系列图像.我的第一次尝试涉及在我的主类中调用停止服务,然后创建并运行IntentService的新实例.但是当我调用StopService时,这个崩溃了.
有没有正确的方法来做到这一点?
我想了解Application对象的生命周期Android,尤其是IntentService.
如果IntentService启动,Application对象是否会随之启动?这个的确切顺序是什么?最后,在这种情况下什么时候会被销毁?
android android-intent android-service android-lifecycle android-intentservice
我在Crashlytics中看到崩溃:
致命异常:java.lang.NullPointerException:尝试在com.myapp.APKOfferQueueManagerIntentService.onHandleIntent(SourceFile:71)上的空对象引用上调用虚拟方法'int android.content.Intent.getIntExtra(java.lang.String,int)' ),位于android.os.Looper.loop(Looper.java:135)的android.os.Handler.dispatchMessage(Handler.java:102)的android.app.IntentService $ ServiceHandler.handleMessage(IntentService.java:65) .os.HandlerThread.run(HandlerThread.java:61)
用空意图触发IntentService怎么可能?
android android-intent android-service android-intentservice
我创建了一个IntentService,如下所示:
public class OrdersSyncService extends IntentService {
private static final String TAG = OrdersSyncService.class.getSimpleName();
private Order orderObject;
public OrdersSyncService() {
super("OrdersSyncService");
}
@Override
protected void onHandleIntent(Intent intent) {
//Util.showToast(getApplicationContext(), "Syncing Orders........");
Log.d(TAG, "I'm running....");
syncOrders();
}
private void syncOrders() {
Database database = CouchBaseHelper.openCouchBaseDB(this);
JSONArray ordersJsonArray = new JSONArray(CouchBaseHelper.retrieveNotSyncedOrders(database));
if (ordersJsonArray.length() != 0) {
uploadOrders(ordersJsonArray.toString());
Log.d(TAG, "Orders syncing started.");
} else {
Log.d(TAG, "Nothing to sync.");
}
}
private void uploadOrders(String ordersJsonArray) {
RetrofitApi.ApiInterface apiInterface = RetrofitApi.getApiInterfaceInstance();
final Call<Order> uploadOrders …Run Code Online (Sandbox Code Playgroud)