当我从中读取源代码时java.io.BufferedInputStream.getInIfOpen(),我很困惑为什么它编写这样的代码:
/**
* Check to make sure that underlying input stream has not been
* nulled out due to close; if not return it;
*/
private InputStream getInIfOpen() throws IOException {
InputStream input = in;
if (input == null)
throw new IOException("Stream closed");
return input;
}
Run Code Online (Sandbox Code Playgroud)
为什么它使用别名而不是in直接使用字段变量,如下所示:
/**
* Check to make sure that underlying input stream has not been
* nulled out due to close; if not return it;
*/
private InputStream getInIfOpen() throws IOException …Run Code Online (Sandbox Code Playgroud) 当我尝试导出选定的数据库文件时,Android studio 检查显示如下错误消息。
Issue while downloading database (word-card): Can't open offline database
`/data/data/com.maxim.wordcard.debug/databases/word-card`
Run Code Online (Sandbox Code Playgroud) 当我学习scanf函数时,这是我的程序:
#include <stdio.h>
int main(int argc, char *argv[]) {
int day, year;
char monthName[20];
printf("separate day by /\n");
scanf("%d/%s/%d", &day, monthName, &year);
printf("%d %s %d\n", day, monthName, year);
printf("separate day by blank\n");
scanf("%d%s%d", &day, monthName, &year);
printf("%d %s %d\n", day, monthName, year);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输入和输出如下:
separate day by /
3/Dec/2016
3 Dec/2016 0
separate day by blank
3 Dec 2016
3 Dec 2016
Run Code Online (Sandbox Code Playgroud)
为什么会出现第二个/标记,零个字符也会出现?有没有办法或工具来分析这样的问题?
今天,我遇到了一个关于共享数据进程间的奇怪问题。我声明MainActivity运行在另一个进程中,将TestApplication中的共享数据写为1,然后启动SubActivity来展示共享数据。不幸的是,SubActivity中显示的值仍然为0,因此我们得出结论,在两个进程中填充了两个TestApplication实例,并且共享数据的读写是相互独立的。实际上,共享数据不再在进程间共享。我的问题是在新进程中开始的活动与原始活动之间的另一个区别是什么,例如关于内存?这是我的代码:
<application
android:name=".TestApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:process="com.rlk.miaoxinli.hellokitty"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SubActivity">
</activity>
</application>
public class TestApplication extends Application {
public int mValue = 0;
}
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private TextView mTextView;
private TestApplication mApplication;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mApplication = (TestApplication) getApplication();
setContentView(R.layout.activity_main);
mTextView = (TextView)findViewById(R.id.first);
mApplication.mValue = 1;
mTextView.setClickable(true);
mTextView.setOnClickListener(this);
}
@Override
protected void onResume() {
super.onResume();
mTextView.setText("" …Run Code Online (Sandbox Code Playgroud) android multiprocessing interprocess android-manifest android-activity