我已经实现了一个片段,它有一个SwipeRefreshLayout作为内容视图.刷新动画在onRefresh处触发,但即使从服务器检索数据后setRefreshing设置为false,它也永远不会停止.
@Override
public void onRefresh() {
handler.post(refreshing);
}
private final Runnable refreshing = new Runnable(){
public void run(){
try {
if(isRefreshing()){
handler.postDelayed(this, 1000);
}else{
swipeLayout.setRefreshing(false);
mainActivity.forceUpdate();
setLayout();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
};
private boolean isRefreshing(){
return swipeLayout.isRefreshing();
}
Run Code Online (Sandbox Code Playgroud) 我正在实现推送通知,但是在调用getToken时我收到了TIMEOUT异常.
我在这里为GCM设置了应用程序,而SENDER_ID正是提供的那个.此外,Server API密钥保存在后端部分.
是否有有限数量的getToken请求?在测试推送通知时,我最初几次尝试都没有问题.
new AsyncTask<Void, Void, Void>(){
@Override
protected Void doInBackground(Void... params) {
try {
InstanceID instance = InstanceID.getInstance(mContext);
String registrationId = instance.getToken(Constants.GCM_SENDER_ID,
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
SharedPreferences sp = mContext.getSharedPreferences(Constants.TOKEN_DATA, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(Constants.REGISTRATION_ID, registrationId);
editor.commit();
NotificationsRegister.getInstance(mContext).register(registrationId);
} catch(IOException e) {
e.printStackTrace();
}
return null;
}
}.execute();
Run Code Online (Sandbox Code Playgroud)
Android清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myexample" >
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET"/>
<permission android:name="com.myexample.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.myexample.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true" …Run Code Online (Sandbox Code Playgroud) 我有一个 ActionBarActivity 和一个 Fragment。Activity 没有膨胀的菜单,而 Fragment 有一个带有两个按钮的菜单。片段菜单可见,但按钮在点击时根本没有反应。在调试时,我可以看到 Fragment 和 Activity 的 onCreateOptionsMenu() 都被调用,但是当点击按钮时,没有 onOptionsItemSelected() 被调用,无论是从 Activity 还是从 Fragment。
活动
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return false;
}
Run Code Online (Sandbox Code Playgroud)
分段
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainActivity = (NavigationActivity)getActivity();
setHasOptionsMenu(true);
}
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState){
return (ScrollView) inflater.inflate(R.layout.tutoring_detail, container, false);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.query_details_menu, menu);
super.onCreateOptionsMenu(menu, inflater); …Run Code Online (Sandbox Code Playgroud) android android-menu android-fragments android-actionbaractivity
文件夹Test包含各种文件和文件夹.我想创建一个只包含Test的子文件夹和文件的jar,而不包含层次结构中的目录名称(Test).
我试过了:
ProcessBuilder createJarProcess2 = new ProcessBuilder("jar", "cMf", "test.jar","test");
p = createJarProcess2.start();
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read any errors from the attempted command
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
p.waitFor();
System.out.println("create jar 2 " + p.exitValue());
Run Code Online (Sandbox Code Playgroud)
但也包括目录的名称.
谢谢