Sunday, 8 September 2013

Activity doesn't start from two different ones but from only one

Activity doesn't start from two different ones but from only one

I have several activities in my app. I'd like to start an activity say A
from other two separate ones, B and C. From B A starts good, from C it
alerts me with ANR advise. Cosidering that:
1. Activities are all declared in the Manifest
2. There are no incoerent castings
This is the ImageButton in activity C from witch activity A should start:
Preferiti.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageButton myButton = (ImageButton)
findViewById(R.id.buttonPreferiti );
Animation anim = new AlphaAnimation(0.0f, 1.0f);// LAMPEGGIO
BOTTONE 1
anim.setDuration(20); //SI PUò CONTROLLARE LA DURATA DEL
LAMPEGGIO CON QUESTO PARAMETRO
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
myButton.startAnimation(anim);
anim.setRepeatCount(5);
Intent i = new Intent(getApplicationContext(),
PreferitiActivity.class);
// i.putExtra(EXTRA_MESSAGE, message);
startActivity(i);
}
});
And this is the activity A that must be opened:
package com.wikibuyers.aforismi;
import java.io.FileNotFoundException;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.Writer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.io.IOException;
import java.util.ArrayList;
public class PreferitiActivity extends Activity{
public final static String EXTRA_MESSAGE = "com.example.provare.MESSAGE";
public String message ;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.preferiti);
// Intent intent = getIntent();
// String message = intent.getStringExtra
(SingolaFraseSelezionataActivity.EXTRA_MESSAGE);
// filename=message;
Reader reader = null;
try {
reader = new InputStreamReader(openFileInput(message));
StringBuffer aux = new StringBuffer();
char[] buf = new char[1024];
int len;
while ((len = reader.read(buf)) != -1) {
aux.append(buf, 0, len);
}
} catch (FileNotFoundException e) {
message = "";
} catch (IOException e) {
Log.e("FileDemo", "Impossibile aprire il file", e);
message = "";
} finally {
if (reader != null) {
try {
reader.close();
} catch (Throwable t) {
}
}
}
ArrayList<String> FrasiAggiuntePreferiti = new ArrayList<String>();
FrasiAggiuntePreferiti.add(message);
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(getApplicationContext(), R.layout.list_item,
FrasiAggiuntePreferiti);
ListView listView = (ListView) findViewById(R.id.listView3);
listView.setAdapter(adapter);
}
}
Please give me some ideas on what it can be! Thanks in advance.

No comments:

Post a Comment