Hello dear StackOverflow community!!!
While developing my recent application project i found some problems while debugging the app. In my project i want to pass one data element through 2 activities. Everything looks good (no errors or other stuff) until i choose WatchingActivity in my app. It displays no webview but only white blank space while there should be video choosen in PartActivity. Please help!!!!
public class MainActivity extends AppCompatActivity {
String clipname;
ImageView ka;
ImageView jb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ka = (ImageView) findViewById(R.id.imageView1);
jb = (ImageView) findViewById(R.id.imageView2);
}
public void imageView1Clicked(View view) {
// method that is signed in layout file to be called by clicking on imageView1
clipname="Kendra's Adventure";
Intent mainintent = new Intent(this, ChooseAPartActivity.class);
mainintent.putExtra("CLIP", clipname);
startActivity(mainintent);
}
public void imageView2Clicked(View view) {
clipname="Johhny Big";
Intent mainintent = new Intent(this, ChooseAPartActivity.class);
mainintent.putExtra("CLIP", clipname);
startActivity(mainintent);
}
}
public class ChooseAPartActivity extends AppCompatActivity {
TextView title;
TextView part1;
TextView part2;
TextView part3;
TextView part4;
TextView part5;
TextView part6;
String videoname;
String partnumber;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choose_a_part);
title.findViewById(R.id.textView);
title.findViewById(R.id.textView);
Intent mainintent = getIntent();
String clipname = mainintent.getStringExtra("CLIP");
title.setText(clipname);
videoname = clipname;
}
public void partone (View view) {
//method assigned to textview in layout file
partnumber = "one";
Intent partintent = new Intent(this, WatchingActivity.class);
partintent.putExtra("PART", videoname);
partintent.putExtra("NUMBER", partnumber);
startActivity(partintent);
}
public void parttwo (View view) {
partnumber = "two";
Intent partintent = new Intent(this, WatchingActivity.class);
partintent.putExtra("PART", videoname);
partintent.putExtra("NUMBER", partnumber);
startActivity(partintent);
}
public void partthree (View view) {
partnumber = "three";
Intent partintent = new Intent(this, WatchingActivity.class);
partintent.putExtra("PART", videoname);
partintent.putExtra("NUMBER", partnumber);
startActivity(partintent);
}
public void partfour (View view) {
partnumber = "four";
Intent partintent = new Intent(this, WatchingActivity.class);
partintent.putExtra("PART", videoname);
partintent.putExtra("NUMBER", partnumber);
startActivity(partintent);
}
public void partfive (View view) {
partnumber = "five";
Intent partintent = new Intent(this, WatchingActivity.class);
partintent.putExtra("PART", videoname);
partintent.putExtra("NUMBER", partnumber);
startActivity(partintent);
}
public void partsix (View view) {
partnumber = "six";
Intent partintent = new Intent(this, WatchingActivity.class);
partintent.putExtra("PART", videoname);
partintent.putExtra("NUMBER", partnumber);
startActivity(partintent);
}
}
public class WatchingActivity extends AppCompatActivity {
String clipkey;
WebView screen;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_watching);
Intent sceneintent = getIntent();
String videoname = partintent.getStringExtra("PART");
String partnumber = sceneintent.getStringExtra("NUMBER");
if(videoname == "Kendra's Adventure"){
if(partnumber == "one"){
clipkey = "<iframe width=\"95%\" height=\"95%\" src=\"links work fine i tried it many times so its not that\" frameborder=\"0\" allowfullscreen></iframe>";
}
}
else if(videoname == "Johnny Big"){
if(partnumber == "one") {
clipkey = "<iframe width=\"95%\" height=\"95%\" src=\"\" frameborder=\"0\" allowfullscreen></iframe>";
}
else if(partnumber == "two"){
clipkey = "<iframe width=\"95%\" height=\"95%\" src=\"\" frameborder=\"0\" allowfullscreen></iframe>";
}
}
screen=(WebView)findViewById(R.id.webView);
screen.getSettings().setJavaScriptEnabled(true);
String myvideokey = clipkey;
screen.loadData(myvideokey, "text/html", "utf-8");
screen.setWebChromeClient(new WebChromeClient(){
});
}
}
String videoname = partintent.getStringExtra("PART");
Is that line ok in WatchingActivity? There is no partintent field or something.
Defining all activities in the same class-file is not really good idea.
Related
This question already has answers here:
How to use SharedPreferences in Android to store, fetch and edit values [closed]
(30 answers)
Closed 5 years ago.
hey guys so i got a login activity that checks username and password with server to authenticate users. i want to use sharedpermissions to store username and password so that the user wont have log in every time. i also want to create a login button.
i tried to implement it but itjust skips login acitivity and takes me to my second activity. i left some of sharedpermission codes as comments (//)
can anyone show/tell me the best i can do it?
public class LoginActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//String username = "";
//String password = "";
//SharedPreferences pre;
final EditText etUsername = (EditText) findViewById(R.id.etUsername);
final EditText etPassword = (EditText) findViewById(R.id.etPassword);
final TextView tvRegisterLink = (TextView) findViewById(R.id.tvRegisterhere);
final Button bLogin = (Button) findViewById(R.id.bLogin);
if(TextUtils.isEmpty(etUsername.getText().toString())||TextUtils.isEmpty(etPassword.getText().toString())){
Intent intent = new Intent(LoginActivity.this, UserAreaActivity.class);
LoginActivity.this.startActivity(intent);
} else {
Intent registerIntent = new Intent(LoginActivity.this, LoginActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
final String username1 = SharedPreferenceUtils.getUsername(this);
final String password1 = SharedPreferenceUtils.getPassword(this);
// pre = getSharedPreferences("pref",MODE_PRIVATE);
//if(pre.getBoolean("username",true) && pre.getBoolean("password",true)){
tvRegisterLink.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
});
bLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String username = etUsername.getText().toString();
final String password = etPassword.getText().toString();
// Response received from the server
Response.Listener<String> responseListener = new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
String name = jsonResponse.getString("name");
SharedPreferenceUtils.createSP(LoginActivity.this,username1,password1);
Intent intent = new Intent(LoginActivity.this, UserAreaActivity.class);
intent.putExtra("name", name);
intent.putExtra("username", username);
LoginActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("Login Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(username, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
queue.add(loginRequest);
}
});
}
}
public class UserAreaActivity extends AppCompatActivity {
#Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_area);
final TextView etusername = (TextView) findViewById(R.id.textView2);
final TextView etwelcome = (TextView) findViewById(R.id.textView);
final ImageButton red = (ImageButton) findViewById(R.id.imageButton);
final ImageButton messages = (ImageButton) findViewById(R.id.imageButton2);
final ImageButton blue = (ImageButton) findViewById(R.id.imageButton3);
final ImageButton ping = (ImageButton) findViewById(R.id.imageButton4);
final TextView etuname = (TextView) findViewById(R.id.textView3);
final Button Logout = (Button) findViewById(R.id.logout);
//String Name = SharedPreferenceUtils.getName(this);
//etwelcome.setText(Name);
red.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent registerIntent = new Intent(UserAreaActivity.this, Report.class);
UserAreaActivity.this.startActivity(registerIntent);
}
});
messages.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent registerIntent = new Intent(UserAreaActivity.this, Messages.class);
UserAreaActivity.this.startActivity(registerIntent);
}
});
Logout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean isClear = SharedPreferenceUtils.clearSP(UserAreaActivity.this);
if(isClear){
Intent registerIntent = new Intent(UserAreaActivity.this, LoginActivity.class);
UserAreaActivity.this.startActivity(registerIntent);
}
}
});
Intent intent = getIntent();
String name = intent.getStringExtra("name");
String username = intent.getStringExtra("username");
String message = "Welcome " + name;
etwelcome.setText(message);
etusername.setText(username);
//Intent in = new Intent(getApplicationContext(), Messages.class);
//in.putExtra("username", username);
//UserAreaActivity.this.startActivity(in);
}
}
You can use SharedPreferences in your code .
Try this .
public class SharedPreferenceUtils {
private static final String SP_NAME = "sp";
public static final String USERNAME = "username";
public static final String PASSWORD = "password";
// create
public static boolean createSP(Context context, String username, String password) {
SharedPreferences.Editor editor = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE).edit();
editor.putString(USERNAME, username);
editor.putString(PASSWORD, password);
return editor.commit();
}
// clear
public static boolean clearSP(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
return editor.clear().commit();
}
// get access info
public static String getUsername(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
return sp.getString(USERNAME, "");
}
// get branch info
public static String getPassword(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
return sp.getString(PASSWORD, "");
}
}
Use in LoginActivity
SharedPreferenceUtils.createSP(this,username,password);
And use in other Activity
String username = SharedPreferenceUtils.getUsername(this);
String password = SharedPreferenceUtils.getPassword(this);
Edit
if (success) {
String name = jsonResponse.getString("name");
SharedPreferenceUtils.createSP(this, username, password);
}
Edit
private EditText etUsername, etPassword;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername = (EditText) findViewById(R.id.etUsername);
etPassword = (EditText) findViewById(R.id.etPassword);
String username = SharedPreferenceUtils.getUsername(this);
String password = SharedPreferenceUtils.getPassword(this);
etUsername.setText(username);
etPassword.setText(password);
}
Edit
if(TextUtils.isEmpty(etUsername.getText().toString())||TextUtils.isEmpty(etPassword.getText().toString())){
Intent intent = new Intent(LoginActivity.this, A.class);
LoginActivity.this.startActivity(intent);
} else {
Intent registerIntent = new Intent(LoginActivity.this, B.class);
LoginActivity.this.startActivity(intent);
}
Edit
boolean isClear = SharedPreferenceUtils.clearSP(UserAreaActivity.this);
if(isClear){
Intent registerIntent = new Intent(UserAreaActivity.this, LoginActivity.class);
UserAreaActivity.this.startActivity(registerIntent);
}
I added a variable that pass form the first activity to the second one.
I want to use the info that has accepted from the first activity, at the new activity, and will save it on new double variable, display it as permanent on a textView.
Now, it appears only when I am clicking on the regular button that start the new activity.
As first step, I guess, I need to remove - "startActivity(intent1);".
How should I move on from here?
Java code:
First Activity (Name : settings.java)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
}
public void onClick (View v){
Intent intent = new Intent(settings.this, WaitressRecord.class);
startActivity(intent);
}
protected void onClickWait (View v) {
//--- Casting & Converting EditText "etSalaryWaitress" to Double "doubleSW".
btnWaitress =(Button)findViewById(R.id.btnWaitress);
etSalaryWaitress = (EditText) findViewById(R.id.etSalaryWaitress);
doubleSW = Double.parseDouble(etSalaryWaitress.getText().toString());
//---Casting Radio Button(s).
rbPercentage = (RadioButton)findViewById(R.id.rbPercentage);
rbShekel = (RadioButton)findViewById(R.id.rbShekel);
if (doubleSW < 100 ) {
if (rbPercentage.isChecked()) {
HafrashaP = 1 - (doubleSW / 100.0);
strHafPer = String.valueOf(HafrashaP);
Toast.makeText(settings.this, strHafPer, Toast.LENGTH_SHORT).show();
// start the SecondActivity
Intent intent1 = new Intent(this, WaitressRecord.class);
intent1.putExtra(Intent.EXTRA_TEXT, strHafPer);
startActivity(intent1);
} else if (rbShekel.isChecked()) {
HafrashaS = -doubleSW;
strHafShek = String.valueOf(HafrashaS);
Toast.makeText(settings.this, strHafShek, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(settings.this, "לא הוזנה סוג ההפרשה", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(settings.this, "מספר שגוי", Toast.LENGTH_SHORT).show();
}
}
New Activity: (Name : WaitressRecord.java)
public class WaitressRecord extends AppCompatActivity {
String strHafPer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_waitress_record);
// get the text from MainActivity
Intent intent1 = getIntent();
strHafPer = intent1.getStringExtra(Intent.EXTRA_TEXT);
// use the text in a TextView
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(strHafPer);
}
}
//First Activity
Intent intent= new Intent(this, SecondActivity.class);
Bundle extra = new Bundle();
mBundle.putString(VARIABLE_KEY, value);
intent.putExtras(mBundle);
startActivity(intent);
//on the second Acitivty
intent intent = getIntent();
Bundle bundleExtra;
//Null Checking
if (intent != null ) {
bundleExtra = getIntent().getExtras();
// Be sure your check your "VARIABLE KEY SAME AS in THE FIRST ACTIVITY
String resultString = extras.getString("VARIABLE_KEY");
}
I am trying to setText() to
Button btnFloor, btnTable;
Which isn't working ATM, actually I'm trying to send data from
FloorsActivity -> TablesActivity -> NewOrdersActivity
So how I pass Data from a activity to another?
FloorsActivity.java
#Override
public void onFloorItemClicked(int id) {
Intent intent = new Intent(this, TablesActivity.class);
intent.putExtra("FloorId", id);
startActivity(intent);
Toast.makeText(this, "Floor id : " + String.valueOf(id), Toast.LENGTH_SHORT).show();
}
TablesActivity.java
int floorId;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_floors_tables);
initViews();
Intent intent = getIntent();
floorId = intent.getIntExtra("FloorId", 1);
}
#Override
public void onTableItemClicked(String name) {
String floorName = "F" + floorId;
Intent intent = new Intent(this, NewOrderActivity.class);
intent.putExtra("FloorId", floorId);
intent.putExtra("TableName", name);
intent.putExtra("FloorName", floorName);
startActivity(intent);
Toast.makeText(this, "Table Name : " + String.valueOf(name), Toast.LENGTH_SHORT).show();
}
NewOrderActivity.java
String floorName;
String tableName;
int floorId;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_order);
initViews();
Intent intent = getIntent();
floorName = intent.getStringExtra("FloorName");
tableName = intent.getStringExtra("TableName");
floorId = intent.getIntExtra("FloorId", 1);
}
public void initViews() {
// Fetch view
btnFloor = (Button) findViewById(R.id.btn_floor);
btnTable = (Button) findViewById(R.id.btn_table);
//Set Views
btnFloor.setText(floorName);
btnTable.setText(tableName);
btnFloor.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(NewOrderActivity.this, FloorsActivity.class);
startActivity(intent);
}
});
btnTable.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(NewOrderActivity.this, TablesActivity.class);
intent.putExtra("FloorId", floorId);
startActivity(intent);
}
});
NewOrdersActivity is where I'm trying to set text
Here is my commit on Github for this full change
Here is the link to this project
You call initViews() before you've overloaded the intent extra's.
Fixed NewOrderActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_order);
Intent intent = getIntent();
floorName = intent.getStringExtra("FloorName");
tableName = intent.getStringExtra("TableName");
floorId = intent.getIntExtra("FloorId", 1);
initViews();
}
I am developing an app with 5 tabs and my last tab displays a list of menus. The problem appears when I click a menu tab, the menu activity appears nicely below my tab but when I click any of the menus (which it will call LoginActivity), the new Activity appears full screen not under the tab. How can I handle this? Below is my code.
TabActivity
package com.smartag.smarttreasure;
public class NfcSurveyActivity extends TabActivity {
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters,
mTechLists);
int profileCount = db.getContactsCount();
if (profileCount <= 0) {
Intent intent = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(intent);
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int profileCount = db.getContactsCount();
if (profileCount <= 0) {
Intent intent1 = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(intent1);
}
Bundle extras = getIntent().getExtras();
if (extras != null) {
tabToDisplay = extras.getString("tab");
if (tabToDisplay.equals("CAMERA")) {
barcodeData = extras.getString("barcodeData");
}
extras.clear();
}
TabHost tabHost = getTabHost();
// Home
TabSpec tbspecHome = tabHost.newTabSpec("Home");
tbspecHome.setIndicator("",
getResources().getDrawable(R.drawable.tab_account_style));
Intent iHome = new Intent(this, HomeActivity.class);
tbspecHome.setContent(iHome);
tabHost.addTab(tbspecHome);
// History
tabHost.addTab(tabHost
.newTabSpec("Fun")
.setIndicator("",
getResources().getDrawable(R.drawable.tab_fun_style))
.setContent(
new Intent(this, NfcSurveyActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
if (tabToDisplay != null && tabToDisplay.equals("REDEEM")) {
if (barcodeData != null && barcodeData.length() > 0) {
tabHost.addTab(tabHost
.newTabSpec("Camera")
.setIndicator(
"",
getResources().getDrawable(
R.drawable.tab_redeem_style))
.setContent(
new Intent(this, NfcSurveyActivity.class)
.addFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP)
.putExtra("autoLoadBarcodeData",
barcodeData)));
}
else {
tabHost.addTab(tabHost
.newTabSpec("Camera")
.setIndicator(
"",
getResources().getDrawable(
R.drawable.tab_redeem_style))
.setContent(
new Intent(this, NfcSurveyActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
}
} else {
tabHost.addTab(tabHost
.newTabSpec("Camera")
.setIndicator(
"",
getResources().getDrawable(
R.drawable.tab_redeem_style))
.setContent(
new Intent(this, NfcSurveyActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
}
// tabHost.setCurrentTab(2);
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = tabHost
.getTabWidget().getChildAt(2).getLayoutParams().height + 19;
// Search
TabSpec tbspecSearch = tabHost.newTabSpec("Finder");
tbspecSearch.setIndicator("",
getResources().getDrawable(R.drawable.tab_finder_style));
Intent iSearch = new Intent(this, NfcSurveyActivity.class);
tbspecSearch.setContent(iSearch);
tabHost.addTab(tbspecSearch);
// Profile
TabSpec tbspecProfile = tabHost.newTabSpec("Quit");
tbspecProfile.setIndicator("",
getResources().getDrawable(R.drawable.tab_quit_style));
Intent iProfile = new Intent(this, NfcSurveyActivity.class);
tbspecProfile.setContent(iProfile);
tabHost.addTab(tbspecProfile);
for (int i = 0; i <= 4; i++) {
tabHost.getTabWidget()
.getChildTabViewAt(i)
.setBackgroundColor(
getResources()
.getColor(android.R.color.transparent));
if (i == 2) {
tabHost.getTabWidget()
.getChildTabViewAt(i)
.setPadding(
tabHost.getTabWidget().getChildTabViewAt(i)
.getPaddingLeft(),
tabHost.getTabWidget().getChildTabViewAt(i)
.getPaddingTop(),
tabHost.getTabWidget().getChildTabViewAt(i)
.getPaddingRight(), 20);
}
}
if (tabToDisplay != null && tabToDisplay.length() > 0) {
if (tabToDisplay.equals("CAMERA")) {
tabHost.setCurrentTab(2);
} else if (tabToDisplay.equals("HISTORY")) {
tabHost.setCurrentTab(1);
}
}
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
NfcSurveyConfiguration.SelectedTab = tabId;
}
});
}
}
MenuActivity
public class HomeActivity extends ListActivity {
static final String[] Account = new String[] { "Point History", "Scan History",
"Reward/Coupon History", "Share/Transfer History", "Personalise" };
String tabToDisplay = "";
String barcodeData = "";
SharedPreferences nfcSurveyConfiguration;
String profileId;
String pleaseWait = "";
protected boolean _taken;
protected File _directory;
protected String _filename;
protected String _fileExtension;
String profileName = "";
String profileEmail = "";
String profileStatus = "";
String profileLanguage = "";
String profileType = "";
DatabaseHandler db = new DatabaseHandler(this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this,
R.layout.listview_item_row, Account));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
//Toast.makeText(getApplicationContext(),
// ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
Intent intent1 = new Intent(getApplicationContext(),
LoginActivity.class);
startActivity(intent1); // This activity appears not in the tab
}
});
}
#Override
public void onPause() {
super.onPause();
NfcSurveyConfiguration.CurrentActiveTab = 0;
}
}
Any suggestion or advice is highly appreciated.
this code inside setOnItemClickListener help me to solve the problem.
View view1 = getLocalActivityManager().startActivity(
"ReferenceName",
new Intent(getApplicationContext(),
YourActivityClass.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
setContentView(view1);
Im having a problem with an app that I built that seems to be related to me using too many final variables in memory, when I test the app in android 2.3 and below it works fine but 4.0 and above it crashes after a while if the list gets too long, what im trying to figure out is a way that I can either bypass making the variables final or a way that can potentially make them null once they arent in view perhaps? below is my code, any help would go a long way thanks
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
final String url = (String) data.get(position).get(4);
final String aviUrl = (String) data.get(position).get(2);
final Date theTime = (Date) data.get(position).get(3);
final String theTweetText = (String) data.get(position).get(1);
final String theRealName = (String) data.get(position).get(0);
final String theScreenName = (String) data.get(position).get(5);
Boolean isRetweeted = (Boolean) data.get(position).get(6);
final Long iD = (Long) data.get(position).get(7);
final Integer totalTweets = (Integer) data.get(position).get(8);
final Integer totalFollowers = (Integer) data.get(position).get(9);
final Integer totalFollowing = (Integer) data.get(position).get(10);
final Long tweetId = (Long) data.get(position).get(11);
Date currentDate = new Date();
if (convertView == null)
vi = inflater.inflate(R.layout.item, null);
if (isRetweeted == true) {
final String theRetweetedTxt = (String) data.get(position).get(12);
final String theRetweetedUser = (String) data.get(position).get(13);
final String theRetweetedImgUrl = (String) data.get(position).get(14);
final String theRetweetedScreenName = (String) data.get(position).get(15);
final Long rTiD = (Long) data.get(position).get(16);
final Integer rTtotalTweets = (Integer) data.get(position).get(17);
final Integer rTtotalFollowers = (Integer) data.get(position).get(18);
final Integer rTtotalFollowing = (Integer) data.get(position).get(19);
final Long rtTweetId = (Long) data.get(position).get(20);
TextView theTweet = (TextView) vi.findViewById(R.id.tweet_text);
TextView username = (TextView) vi.findViewById(R.id.username);
TextView realname = (TextView) vi.findViewById(R.id.realname);
TextView theTimeTv = (TextView) vi.findViewById(R.id.theTime);
ImageView aviimage = (ImageView) vi.findViewById(R.id.user_avatar);
ImageView image = (ImageView) vi.findViewById(R.id.imageView1);
ImageView retweeterimage = (ImageView) vi
.findViewById(R.id.retweeter_avatar);
ImageView replyImage = (ImageView) vi.findViewById(R.id.mentionbutton);
ImageView retweetImage = (ImageView) vi.findViewById(R.id.retweetbutton);
RelativeLayout profileImageLayout = (RelativeLayout) vi.findViewById(R.id.profileimagelayout);
profileImageLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, FriendProfileActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", rTiD);
intent.putExtra("totaltweets", rTtotalTweets);
intent.putExtra("totalfollowers", rTtotalFollowers);
intent.putExtra("totalfollowing", rTtotalFollowing);
intent.putExtra("useravatar", theRetweetedImgUrl);
intent.putExtra("username", theRetweetedUser);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
context.startActivity(intent);
}
});
image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, LightboxActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("thetweet", theRetweetedTxt);
intent.putExtra("theimage", url);
intent.putExtra("theuserid", rTiD);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
context.startActivity(intent);
}
});
replyImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", rTiD);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
intent.putExtra("isretweet", false);
context.startActivity(intent);
}
});
retweetImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", rTiD);
intent.putExtra("screenname", theRetweetedScreenName);
intent.putExtra("tweetid", rtTweetId);
intent.putExtra("isretweet", true);
intent.putExtra("thetweet", theRetweetedTxt);
context.startActivity(intent);
}
});
String str = (String) DateUtils.getRelativeTimeSpanString(theTime.getTime(), currentDate.getTime(),
0L, DateUtils.FORMAT_ABBREV_ALL);
theTimeTv.setText(str);
theTweet.setText(theRetweetedTxt);
username.setText("RT by #" + theScreenName);
realname.setText("#" + theRetweetedScreenName);
imageLoader.DisplayImage(theRetweetedImgUrl, aviimage);
imageLoader.DisplayImage(url, image);
imageLoader.DisplayImage(aviUrl, retweeterimage);
return vi;
} else {
TextView theTweet = (TextView) vi.findViewById(R.id.tweet_text);
TextView username = (TextView) vi.findViewById(R.id.username);
TextView realname = (TextView) vi.findViewById(R.id.realname);
TextView theTimeTv = (TextView) vi.findViewById(R.id.theTime);
ImageView aviimage = (ImageView) vi.findViewById(R.id.user_avatar);
ImageView image = (ImageView) vi.findViewById(R.id.imageView1);
ImageView replyImage = (ImageView) vi.findViewById(R.id.mentionbutton);
ImageView retweetImage = (ImageView) vi.findViewById(R.id.retweetbutton);
RelativeLayout profileImageLayout = (RelativeLayout) vi.findViewById(R.id.profileimagelayout);
profileImageLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, FriendProfileActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", iD);
intent.putExtra("totaltweets", totalTweets);
intent.putExtra("totalfollowers", totalFollowers);
intent.putExtra("totalfollowing", totalFollowing);
intent.putExtra("useravatar", aviUrl);
intent.putExtra("username", theRealName);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
context.startActivity(intent);
}
});
image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, LightboxActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("thetweet", theTweetText);
intent.putExtra("theimage", url);
intent.putExtra("theuserid", iD);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
context.startActivity(intent);
}
});
replyImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", iD);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
intent.putExtra("isretweet", false);
context.startActivity(intent);
}
});
retweetImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
Intent intent=new Intent(context, TweetScreenActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("theuserid", iD);
intent.putExtra("screenname", theScreenName);
intent.putExtra("tweetid", tweetId);
intent.putExtra("isretweet", true);
intent.putExtra("thetweet", theTweetText);
context.startActivity(intent);
}
});
ImageView retweeterimage = (ImageView) vi
.findViewById(R.id.retweeter_avatar);
retweeterimage.setImageBitmap(null);
String str = (String) DateUtils.getRelativeTimeSpanString(theTime.getTime(), currentDate.getTime(),
0L, DateUtils.FORMAT_ABBREV_ALL);
theTimeTv.setText(str);
theTweet.setText(theTweetText);
username.setText(theRealName);
realname.setText("#" + theScreenName);
imageLoader.DisplayImage(aviUrl, aviimage);
imageLoader.DisplayImage(url, image);
return vi;
}
}
the 'final' keyword won't affect anything, it just basically tells the JVM that the value will not change, so your problem lies elsewhere.