毎日何かをするアプリケーションを作りたいです。私はなんとかその日を救うことができました、そして、次の日で、そして私はそれを今日と比較したいです。
例:日= 5; aux = 5;
明日:
日=6; aux = 5;
If(day!= aux)何か他のことをするなら、何かをしないでください
AUXの状態をSDカードのファイルに保存したかったのですが、動作するコードを見つけるのはとても難しいです。誰かが見て答えてくれることを願っています。明日のために必要です。
public class Castle extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.castle);
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
int aux=Reading();
if(day==aux)
{
Intent intent = new Intent(Castle.this, Hug.class);
startActivity(intent);
}
else
{
Intent intent = new Intent(Castle.this, Hug_Accepted.class);
startActivity(intent);
try {
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()){
File file = new File(root, "Tedehlia/state.txt");
file.mkdir();
FileWriter filewriter = new FileWriter(file);
BufferedWriter out = new BufferedWriter(filewriter);
out.write(day);
out.close();
}
} catch (IOException e) {
}}
}
public int Reading()
{int aux = 0;
try{
File f = new File(Environment.getExternalStorageDirectory()+"/state.txt");
FileInputStream fileIS = new FileInputStream(f);
BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS));
String readString = new String();
if((readString = buf.readLine())!= null){
aux=Integer.parseInt(readString.toString());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
return aux;
}
}