我已经实现了一个调用服务的AlarmManager.问题是虽然我在AsyncTask中启动它,但它阻止了主线程.这是我的AsyncTask的来源:
private class NotificationsServiceTask extends AsyncTask<Void, Void, Void> {
private AlarmManager alarmMgr;
private PendingIntent pi;
@Override
protected Void doInBackground(Void... params) {
alarmMgr = (AlarmManager) LoginActivity.this.getSystemService(Context.ALARM_SERVICE);
Intent serviceIntent = new Intent(LoginActivity.this, Service.class);
pi = PendingIntent.getService(LoginActivity.this, 0, serviceIntent, 0);
alarmMgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), 120000, pi);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要异步执行它,因为它阻塞了我的主线程.
在我的Android项目中使用Volley,我得到一个json响应,如:
{
"value1": 1,
"value2": aaa,
"subvalues": [
{
"value1": 297,
"value2": 310,
"class3": {
"name": "name1",
"id": 1,
"value": 32
}
},
...
]
}
Run Code Online (Sandbox Code Playgroud)
我需要使用Gson将其反序列化为pojo.课程是:
1类:
public class class1 {
private int value1;
private String value2;
private List<class2> vals;
public class class2 {
private int value1;
private int value2;
private class3 c3;
}
}
Run Code Online (Sandbox Code Playgroud)
CLASS3:
public class class3 {
private String name;
private int id;
private int value;
}
Run Code Online (Sandbox Code Playgroud)
打电话后
Gson g = new Gson();
class1 c1 = …Run Code Online (Sandbox Code Playgroud) 我正在使用一个实时应用程序,其中包含应用程序中的选项卡.当我尝试在纵向和横向之间切换方向时,我有代码显示横向的单独布局.为此,我使用了onConfigurationChanged如下方法
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT){
setContentView(R.layout.eventslist);
}else if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
setContentView(R.layout.eventstimeline);
}
}
Run Code Online (Sandbox Code Playgroud)
而且在该特定活动的清单文件中,我使用了两个属性,如下所示
android:screenOrientation="sensor"
android:configChanges="orientation|keyboardHidden"
Run Code Online (Sandbox Code Playgroud)
但是当我旋转设备时,我无法看到我指定的横向模式的单独布局onConfigurationChanged.此外,我不希望在横向模式下看到选项卡.对此有任何想法.
我正在我的应用程序内部的GUI上工作.我原本看起来很糟糕,它只包含了测试我的java函数的所有基本内容.在我完成所有函数运行之后,我使用Eclipse中的图形编辑器重新编写了GUI.下次我运行我的应用程序时,我的android.webkit.WebView无法在我的LogCat中强制转换为android.widget.Button.我没有改变java中的任何内容,并且GUI中的所有声明都是相同的,据我所知.我可以轻松地将GUI恢复到糟糕的版本,但这对我没什么帮助.我希望这里有人可以帮我找到问题所在.我发布了xml,java和LogCat.
05-09 13:25:19.756: E/AndroidRuntime(10424): FATAL EXCEPTION: main
05-09 13:25:19.756: E/AndroidRuntime(10424): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.dcc/com.example.dcc.ActionItem}:
java.lang.ClassCastException: android.webkit.WebView cannot be cast to android.widget.Button
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.access$600(ActivityThread.java:130)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.os.Looper.loop(Looper.java:137)
05-09 13:25:19.756: E/AndroidRuntime(10424): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-09 13:25:19.756: E/AndroidRuntime(10424): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 13:25:19.756: E/AndroidRuntime(10424): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 13:25:19.756: E/AndroidRuntime(10424): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-09 13:25:19.756: E/AndroidRuntime(10424): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-09 …Run Code Online (Sandbox Code Playgroud)