하나의 활동에 파일로 내용을 쓰고 다른 활동으로 읽으려는 시도를하고 있습니다. 사실, 사용자는 수신자의 번호를 한 번 입력해야합니다. 그 후, 난 내 오류이고, 내가 어제부터 시도 ... 자동 그를 위해 내가 모르는하나의 활동으로 파일을 작성하고 다른 활동에서 읽음
을이받는 사람의 번호를 입력합니다 ... 은 .. 당신의 도움을 주셔서 대단히 감사
package com.example.automatik;
공용 클래스 AddRecipientNumber는 활동 {
//On stocke le n° du destinataire (1)
String FILENAME = "recipientnumber.txt";
String mehmet = "mehmetmehmet";
FileOutputStream fos;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_recipient_number);
// Show the Up button in the action bar.
setupActionBar();
Button button = (Button)findViewById(R.id.recipientbutton1);
button.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(final View v)
{
EditText textA = (EditText)findViewById(R.id.recipientedit1);
String a = textA.getText().toString();
EditText textB = (EditText)findViewById(R.id.recipientedit2);
String b = textB.getText().toString();
if(a.equals(b))
{
//On stocke le n° du destinataire (2)
try
{
fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(mehmet.getBytes());
fos.close();
}
catch (FileNotFoundException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
AlertDialog alertdialog = new AlertDialog.Builder(AddRecipientNumber.this).create();
alertdialog.setMessage("You entered these numbers correctly.\nNow, we will move to the second step!");
alertdialog.setButton("Move", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
sendMove(v);
}
});
alertdialog.show();
}
else
{
AlertDialog alertdialog = new AlertDialog.Builder(AddRecipientNumber.this).create();
alertdialog.setMessage("These numbers must be identical. \nPlease try again.");
alertdialog.show();
}
}
});
}
//Une fois que les numéros entrés sont identiques & que l'utilisateur accepte de passer à la 2nde étape, on lance:
public void sendMove(View v)
{
Intent intent = new Intent(this, AddMasterNumber.class);
startActivity(intent);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
내 두 번째 활동 확장 :
패키지 com.example.automatik을;
공용 클래스 AddMasterNumber 당신은 당신이 달성하고자하는 것을 위해 파일을 필요로하지 않는 활동 {
String finall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_master_number);
// Show the Up button in the action bar.
//setupActionBar();
//On récupère le n° du destinataire stocké
try
{
FileInputStream in = openFileInput("recipientnumber.txt");
StringBuffer fileContent = new StringBuffer("");
byte[] buffer = new byte[1024];
while(in.read(buffer) != -1)
{
fileContent.append(new String(buffer));
}
in.close();
finall = fileContent.toString();
}
catch (FileNotFoundException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
TextView text = (TextView)findViewById(R.id.recipienttext3);
text.setText(finall);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
후 로그 캣 오류 출력. 그러면 오류의 위치가 표시됩니다. – Neoh
원하는 것을 달성하려고합니다. 대신에 sharedpreferences를 사용할 수 없습니까? 또는 응용 프로그램 클래스와 원하는 위치에서 액세스 할 수 있습니까? – qwr
QWR : 한 활동에 파일을 쓰고 다른 활동으로 읽으려고합니다 ... 예를 들어 첫 활동에서 사용자가 수신자 번호를 입력하고 & nbsp; 그 후, 사용자가 친구에게 SMS를 보낼 필요가있을 때마다 나는 그 사람의 수를 자동으로 입력합니다 ... – d3vpasha