I have MainActivity with two String variables viz. filename & url.
I tried to use one download manager.
I dont know how to pass filename String from my Player Activity.
buttondownload = (TextView )findViewById(R.id.download);
buttondownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
DownloadHelper.addNewTask(Player.this, url,
new PreDownloadStatusListener() {
#Override
public void notFoundSDCard(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "No SD Card", Toast.LENGTH_SHORT).show();
}
#Override
public void sdCardCannotWriteOrRead(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Not read and write SD card", Toast.LENGTH_SHORT).show();
}
#Override
public void moreTaskCount(int errorCode, String errorInfo) {
Toast.makeText(Player.this, "Task list is full", Toast.LENGTH_SHORT).show();
}
});
Intent intent1 = new Intent(Player.this, DownloadListActivity.class);
startActivity(intent1);
}
});
DownloadHelper.startAllTask(Player.this);
mReceiver = new DownloadReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(DownloadValues.Actions.BROADCAST_RECEIVER_ACTION);
registerReceiver(mReceiver, filter);
They call filename from another public class DownloadUtils.. How can i pass filname to DownloadUtils
I want Pass String from Player to ViewHolder.java
package com.download.main;
public class ViewHolder {
public static final int KEY_URL = 0;
public static final int KEY_SPEED = 1;
public static final int KEY_PROGRESS = 2;
public static final int KEY_IS_PAUSED = 3;
public TextView titleText;
public ProgressBar progressBar;
public TextView speedText;
public ImageButton pauseButton;
public ImageButton deleteButton;
public ImageButton continueButton;
private boolean hasInited = false;
public ViewHolder(View parentView) {
if (parentView != null) {
titleText = (TextView) parentView.findViewById(R.id.title);
speedText = (TextView) parentView.findViewById(R.id.speed);
progressBar = (ProgressBar) parentView.findViewById(R.id.progress_bar);
pauseButton = (ImageButton) parentView.findViewById(R.id.btn_pause);
deleteButton = (ImageButton) parentView.findViewById(R.id.btn_delete);
continueButton = (ImageButton) parentView.findViewById(R.id.btn_continue);
hasInited = true;
}
}
public static HashMap<Integer, String> getItemDataMap(String url, String speed, String progress, String isPaused) {
HashMap<Integer, String> item = new HashMap<Integer, String>();
item.put(KEY_URL, url);
item.put(KEY_SPEED, speed);
item.put(KEY_PROGRESS, progress);
item.put(KEY_IS_PAUSED, isPaused);
return item;
}
public void setData(HashMap<Integer, String> item) {
if (hasInited) {
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(item.get(KEY_SPEED));
String progress = item.get(KEY_PROGRESS);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(progress));
}
if (Boolean.parseBoolean(item.get(KEY_IS_PAUSED))) {
onPause();
}
}
}
public void onPause() {
if (hasInited) {
pauseButton.setVisibility(View.GONE);
continueButton.setVisibility(View.VISIBLE);
}
}
public void setData(String url, String speed, String progress) {
setData(url, speed, progress, false + "");
}
public void setData(String url, String speed, String progress, String isPaused) {
if (hasInited) {
HashMap<Integer, String> item = getItemDataMap(url, speed, progress, isPaused);
titleText.setText(///////**I want here my my string calle "filename" from player Activity**//////);
speedText.setText(speed);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(item.get(KEY_PROGRESS)));
}
}
}
}
To pass any data from one activity to another use Intent. Example:-
Use below code in your Player.java class:-
Intent intent = new Intent(FromClass.this, ToClass.class);
intent.putExtra("filename", filename);
startActivity(intent);
Write the below code in the ViewHolder.java class:-
do not forget to extend Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayoutName);
Intent intent = getIntent();
String filename= intent.getStringExtra("filename");
}
Then you can use filename in your setData() like this:-
public void setData(HashMap<Integer, String> item) {
if (hasInited) {
titleText.setText(filename);
speedText.setText(item.get(KEY_SPEED));
String progress = item.get(KEY_PROGRESS);
if (TextUtils.isEmpty(progress)) {
progressBar.setProgress(0);
}
else {
progressBar.setProgress(Integer.parseInt(progress));
}
if (Boolean.parseBoolean(item.get(KEY_IS_PAUSED))) {
onPause();
}
}
}
Related
How to get the data from server and upload data to server using JSON?
please tell me.
This is QRActivity------------------------------------------------
final View.OnClickListener listener = new View.OnClickListener() {
#Override
public
void onClick(View v) {
btnSearch.setClickable(true);
// Server call with record_id
//DistributionDetails detDis <-- response json object from server call
QrActivityViewDetails detDis = new
QrActivityViewDetails(1002,"NORORG147530","No2,abcd Road , Colombo 03","0112233456");
Intent myIntent = new Intent(QrActivity.this, DistributionDetails.class);
myIntent.putExtra("QrActivityViewDetails", detDis);
startActivity(myIntent);
}
};
This is QrActivityViewDetails Class file
public class QrActivityViewDetails implements Serializable {
#SerializedName("DistributionID")
private int DistributionID;
#SerializedName("full_name")
private String full_name;
#SerializedName("full_address")
private String full_address;
#SerializedName("contact")
private String contact;
public QrActivityViewDetails(int DistributionID, String full_name, String full_address, String contact_number)
{
this.DistributionID = DistributionID;
this.full_name = full_name;
this.full_address = full_address;
this.contact = contact_number;
}
public
int getRecord_id() {
return DistributionID;
}
public
void setRecord_id(int record_id) {
this.DistributionID = record_id;
}
public
String getFull_name() {
return full_name;
}
public
void setFull_name(String full_name) {
this.full_name = full_name;
}
public
String getFull_address() {
return full_address;
}
public
void setFull_address(String full_address) {
this.full_address = full_address;
}
public
String getContact() {
return contact;
}
public
void setContact(String contact) {
this.contact = contact;
}
}
This is View Data Activity called DistributionDetails---------------
public class DistributionDetails extends AppCompatActivity {
private QrActivityViewDetails detQRV;
TextView ID ,Address ,name,contact;
Button btnDIR;
#Override
protected
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_distribution_details);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
ID = (TextView) findViewById(R.id.lblID);
Address = (TextView) findViewById(R.id.lblAddress);
name = (TextView) findViewById(R.id.lblUname);
contact = (TextView) findViewById(R.id.lblTelenum);
btnDIR = (Button) findViewById(R.id.btnDelivered);
IntendFill();
btnDIR.setOnClickListener(new View.OnClickListener() {
#Override
public
void onClick(View v) {
Intent intent = new Intent(DistributionDetails.this, FinalActivity.class);
startActivity(intent);
}
});
}
public void IntendFill() {
Intent intent = getIntent();
if (intent.hasExtra("QrActivityViewDetails")) {
detQRV = (QrActivityViewDetails) intent.getSerializableExtra("QrActivityViewDetails");
ID.setText(String.valueOf(detQRV.getRecord_id()));
Address.setText(String.valueOf(detQRV.getFull_address()));
name.setText(String.valueOf(detQRV.getFull_name()));
contact.setText(String.valueOf(detQRV.getContact()));
}
}
}
I'm trying to get working a native android project that uses Worklight form based authentication. I'm already able to authenticate the user through the native APIs. The problem appears when I change between activities (intents). Once the user enters his information and submits the form, it is authenticated but the worklight server connection is lost.
This is the code:
MainActivity.java
public class MainActivity extends Activity {
private Button buttonConnect = null;
private Button buttonInvoke = null;
private static TextView textView = null;
private static MainActivity _this;
private MyChallengeHadler challengeHandler;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_this = this;
buttonConnect = (Button)findViewById(R.id.buttonConnect);
buttonInvoke = (Button)findViewById(R.id.buttonInvoke);
textView = (TextView)findViewById(R.id.textView);
final WLClient client = WLClient.createInstance(this);
buttonConnect.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
updateTextView("Connecting...");
client.connect(new MyConnectListener());
challengeHandler = new MyChallengeHadler(MainActivity.this, "BasicAuth");
client.registerChallengeHandler(challengeHandler);
}
});
buttonInvoke.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
updateTextView("Invoking procedure...");
String adapterName = "RSSReader";
String procedureName = "getStoriesFiltered";
WLProcedureInvocationData invocationData =
new WLProcedureInvocationData(adapterName, procedureName);
Object[] parameters = new Object[] {"world"};
invocationData.setParameters(parameters);
WLRequestOptions options = new WLRequestOptions();
options.setTimeout(30000);
WLClient client = WLClient.getInstance();
client.invokeProcedure(invocationData, new MyInvokeListener(), options);
}
});
}
public static void updateTextView(final String str){
Runnable run = new Runnable() {
public void run() {
textView.setText(str);
}
};
_this.runOnUiThread(run);
}
}
LoginActivity.java
public class LoginActivity extends Activity {
private Button Submit = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Submit = (Button)findViewById(R.id.button1);
Submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
MyChallengeHadler challengeHandler = new MyChallengeHadler(LoginActivity.this, "BasicAuth");
challengeHandler.submitLogin(0, "maria", "maria", false);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
MyChallengeHadler.java
public class MyChallengeHadler extends ChallengeHandler {
private WLResponse cachedResponse;
private final Activity parentActivity;
public MyChallengeHadler(final Activity a, String realm) {
super(realm);
this.parentActivity =a;
// TODO Auto-generated constructor stub
}
#Override
public void onFailure(WLFailResponse arg0) {
// TODO Auto-generated method stub
}
#Override
public void onSuccess(WLResponse arg0) {
// TODO Auto-generated method stub
}
#Override
public boolean isCustomResponse(WLResponse response) {
if (response == null || response.getResponseText() == null
|| response.getResponseText().indexOf("j_security_check") == -1) {
return false;
}
return true;
}
#Override
public void handleChallenge(WLResponse response){
if (!isCustomResponse(response)) {
submitSuccess(response);
} else {
cachedResponse = response;
Intent login = new Intent(parentActivity, LoginActivity.class);
parentActivity.startActivityForResult(login, 1);
}
}
public void submitLogin(int resultCode, String userName, String password, boolean back){
HashMap<String, String> params = new HashMap<String, String>();
params.put("j_username", userName);
params.put("j_password", password);
submitLoginForm("/j_security_check", params, null, 0, "post");
Intent login = new Intent(parentActivity, MainActivity.class);
parentActivity.startActivityForResult(login, 1);
}
}
I have already solved my code's problem. I was using wrongly android's intents. This is the new version of the code:
LoginActivity.java
public class LoginActivity extends Activity {
private Button Submit;
private Intent result;
public static final String Back = "back";
public static final String UserNameExtra = "username";
public static final String PasswordExtra = "password";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Submit = (Button)findViewById(R.id.button1);
result = new Intent();
Submit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
result.putExtra(UserNameExtra, "maria");
result.putExtra(PasswordExtra, "maria");
result.putExtra(Back, false);
setResult(RESULT_OK, result);
finish();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
MainActivity.java
public class MainActivity extends Activity {
private Button buttonConnect = null;
private Button buttonInvoke = null;
private static TextView textView = null;
private static MainActivity _this;
private MyChallengeHadler challengeHandler;
private String realm = "BasicAuth";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_this = this;
buttonConnect = (Button)findViewById(R.id.buttonConnect);
buttonInvoke = (Button)findViewById(R.id.buttonInvoke);
textView = (TextView)findViewById(R.id.textView);
final WLClient client = WLClient.createInstance(this);
buttonConnect.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
updateTextView("Connecting...");
client.connect(new MyConnectListener());
challengeHandler = new MyChallengeHadler(MainActivity.this, realm);
client.registerChallengeHandler(challengeHandler);
}
});
buttonInvoke.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
updateTextView("Invoking procedure...");
String adapterName = "SOAPAdapter";
String procedureName = "getStories";
WLProcedureInvocationData invocationData =
new WLProcedureInvocationData(adapterName, procedureName);
//Object[] parameters = new Object[] {"world"};
//invocationData.setParameters(parameters);
WLRequestOptions options = new WLRequestOptions();
options.setTimeout(30000);
WLClient client = WLClient.getInstance();
client.invokeProcedure(invocationData, new MyResponseListener(), options);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
boolean back = data.getBooleanExtra(LoginActivity.Back, true);
String username = data.getStringExtra(LoginActivity.UserNameExtra);
String password = data.getStringExtra(LoginActivity.PasswordExtra);
challengeHandler.submitLogin(resultCode, username, password, back);
}
public static void updateTextView(final String str){
Runnable run = new Runnable() {
public void run() {
textView.setText(str);
}
};
_this.runOnUiThread(run);
}
}
MyChallengeHadler.java
public class MyChallengeHadler extends ChallengeHandler {
private WLResponse cachedResponse;
private final Activity parentActivity;
public MyChallengeHadler(final Activity a, String realm) {
super(realm);
parentActivity =a;
// TODO Auto-generated constructor stub
}
#Override
public void onFailure(WLFailResponse arg0) {
// TODO Auto-generated method stub
}
#Override
public void onSuccess(WLResponse arg0) {
// TODO Auto-generated method stub
}
#Override
public boolean isCustomResponse(WLResponse response) {
if (response == null || response.getResponseText() == null
|| response.getResponseText().indexOf("j_security_check") == -1) {
return false;
}
return true;
}
#Override
public void handleChallenge(WLResponse response){
if (!isCustomResponse(response)) {
submitSuccess(response);
} else {
cachedResponse = response;
Intent login = new Intent(parentActivity, LoginActivity.class);
parentActivity.startActivityForResult(login, 1);
}
}
public void submitLogin(int resultCode, String userName, String password, boolean back){
if (resultCode != Activity.RESULT_OK || back) {
submitFailure(cachedResponse);
} else {
HashMap<String, String> params = new HashMap<String, String>();
params.put("j_username", userName);
params.put("j_password", password);
submitLoginForm("/j_security_check", params, null, 0, "post");
}
}
}
I have a problem with share facebook link. All the time i click on it says
"Unfortunately, this page is not available. Did you get a broken link or page has been deleted."
public static final String FACEBOOK_SHARE_ACTION_LINK = "https://google.com"; // =)
EdiTED
publishing Image
public class FacebookActivity extends Activity {
private FacebookFacade facebook;
private FacebookEventObserver facebookEventObserver;
private TextView messageView;
private String link;
private String linkName;
private String linkDescription;
private String picture;
private Map<String, String> actionsMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_facebook);
facebook = new FacebookFacade(this, Constants.FACEBOOK_APP_ID);
facebookEventObserver = FacebookEventObserver.newInstance();
messageView = (TextView) findViewById(R.id.message);
TextView linkNameView = (TextView) findViewById(R.id.link_name);
TextView linkDescriptionView = (TextView) findViewById(R.id.link_description);
//Button postButton = (Button) findViewById(R.id.button_post);
Button postImageButton = (Button) findViewById(R.id.button_post_image);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String message = bundle.getString(Extra.POST_MESSAGE);
link = bundle.getString(Extra.POST_LINK);
linkName = bundle.getString(Extra.POST_LINK_NAME);
linkDescription = bundle.getString(Extra.POST_LINK_DESCRIPTION);
picture = bundle.getString(Extra.POST_PICTURE);
actionsMap = new HashMap<String, String>();
actionsMap.put(Constants.FACEBOOK_SHARE_ACTION_NAME, Constants.FACEBOOK_SHARE_ACTION_LINK);
messageView.setText(message);
linkNameView.setText(linkName);
linkDescriptionView.setText(linkDescription);
}
postImageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (facebook.isAuthorized()) {
publishImage();
finish();
} else {
// Start authentication dialog and publish image after successful authentication
facebook.authorize(new AuthListener() {
#Override
public void onAuthSucceed() {
publishImage();
finish();
}
#Override
public void onAuthFail(String error) { // Do noting
}
});
}
}
});
}
//private void publishMessage() {
//facebook.publishMessage(messageView.getText().toString(), link, linkName, linkDescription, picture, actionsMap);
//}
private void publishImage() {
Bitmap bmp = ((BitmapDrawable) getResources().getDrawable(R.drawable.howmuchcanufarm)).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
facebook.publishImage(bitmapdata, Constants.FACEBOOK_SHARE_IMAGE_CAPTION);
}
#Override
public void onStart() {
super.onStart();
facebookEventObserver.registerListeners(this);
if (!facebook.isAuthorized()) {
facebook.authorize();
}
}
#Override
public void onStop() {
facebookEventObserver.unregisterListeners();
super.onStop();
}
}
i'm stuck with implementing following youtube method.
public abstract void loadVideos (List<String> videoIds)
Loads and plays a list of videos.
basically this is part of my code.
My ultimate goal is when user click on listitem that video plays or it automatically plays all three videos.
Can someone please help me.
private static final String1[] arry = {
new String1("Androidify App", "irH3OSOskcE", false),
new String1("Chrome Speed Tests", "nCgQDjiotG0", false),
new String1("Playlist: Google I/O 2012", "PL56D792A831D0C362", true)};
private static final String KEY_CURRENTLY_SELECTED_ID = "currentlySelectedId";
private YouTubePlayerView youTubePlayerView;
private YouTubePlayer player;
private ArrayAdapter<String1> videoAdapter1;
private ListView videoChooser1;
private StringBuilder logString;
private MyPlayerStateChangeListener playerStateChangeListener;
private MyPlaylistEventListener playlistEventListener;
private int currentlySelectedPosition;
private String currentlySelectedId;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_controls_demo);
youTubePlayerView = (YouTubePlayerView) findViewById(R.id.youtube_view);
videoChooser1 = (ListView) findViewById(R.id.listView1);
logString = new StringBuilder();
videoAdapter1 = new ArrayAdapter<String1>(this, android.R.layout.simple_list_item_1, arry);
videoChooser1.setAdapter(videoAdapter1);
videoChooser1.setOnItemClickListener(this);
youTubePlayerView.initialize(DeveloperKey.DEVELOPER_KEY, this);
playlistEventListener = new MyPlaylistEventListener();
playerStateChangeListener = new MyPlayerStateChangeListener();
}
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
this.player = player;
player.setPlaylistEventListener(playlistEventListener);
player.setPlayerStateChangeListener(playerStateChangeListener);
if (!wasRestored) {
playVideoAtSelection();
}
}
#Override
protected YouTubePlayer.Provider getYouTubePlayerProvider() {
return youTubePlayerView;
}
private void playVideoAtSelection() {
String1 selectedEntry = videoAdapter1.getItem(currentlySelectedPosition);
if (selectedEntry.id != currentlySelectedId && player != null) {
currentlySelectedId = selectedEntry.id;
if (selectedEntry.isPlaylist) {
player.loadPlaylist(selectedEntry.id);
} else {
player.loadVideo(selectedEntry.id);
player.loadVideos(List<String>,selectedEntry.id);
}
}
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id)
{
currentlySelectedPosition = pos;
playVideoAtSelection();
}
#Override
protected void onSaveInstanceState(Bundle state) {
super.onSaveInstanceState(state);
state.putString(KEY_CURRENTLY_SELECTED_ID, currentlySelectedId);
}
#Override
protected void onRestoreInstanceState(Bundle state) {
super.onRestoreInstanceState(state);
currentlySelectedId = state.getString(KEY_CURRENTLY_SELECTED_ID);
}
private void log(String message) {
logString.append(message + "\n");
// eventLog.setText(logString);
}
private final class MyPlaylistEventListener implements PlaylistEventListener {
#Override
public void onNext() {
log("NEXT VIDEO");
}
#Override
public void onPrevious() {
log("PREVIOUS VIDEO");
}
#Override
public void onPlaylistEnded() {
log("PLAYLIST ENDED");
}
}
private final class MyPlayerStateChangeListener implements PlayerStateChangeListener {
String playerState = "UNINITIALIZED";
#Override
public void onLoading() {
playerState = "LOADING";
log(playerState);
}
#Override
public void onLoaded(String videoId) {
playerState = String.format("LOADED %s", videoId);
log(playerState);
}
#Override
public void onAdStarted() {
playerState = "AD_STARTED";
log(playerState);
}
#Override
public void onVideoStarted() {
playerState = "VIDEO_STARTED";
log(playerState);
}
#Override
public void onVideoEnded() {
playerState = "nCgQDjiotG0";
log(playerState);
}
#Override
public void onError(ErrorReason arg0) {
// TODO Auto-generated method stub
}
}
private static final class String1 {
public final String title;
public final String id;
public final boolean isPlaylist;
public String1(String title, String videoId, boolean isPlaylist) {
this.title = title;
this.id = videoId;
this.isPlaylist = isPlaylist;
}
#Override
public String toString() {
return title;
}
}
After few tries i figured it out, it is partially working in case if anyone else needs it
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored) {
this.player = player;
player.setPlaylistEventListener(playlistEventListener);
player.setPlayerStateChangeListener(playerStateChangeListener);
if (!wasRestored) {
ArrayList arrayList = new ArrayList();
arrayList.add((Object)("irH3OSOskcE"));
arrayList.add((Object)("nCgQDjiotG0"));
arrayList.add((Object)("irH3OSOskcE"));
player.loadVideos((List)(arrayList));
//playVideoAtSelection();
}
}
I have a about class in my app to show some button and when the user click on the button it jump to a webview activity to view some webpage so I defined urls in the about class, then set onlick method to deliver them to the same webview activity to open the web page, but I keep getting a curious NullPointerException when running this activity and my logcat print nothing but
12-02 09:03:11.815: WARN/ActivityManager(51): Activity idle timeout
for HistoryRecord{44d68ea0 com.appkon.hdtvs/.About} 12-02
09:03:17.026: WARN/ActivityManager(51): Activity destroy timeout for
HistoryRecord{44e37518 com.appkon.hdtvs/.HDtvs}
Here are my code.Any help would be appreciated, thank you
About.java
public class About extends Activity{
private Button backbutton;
private Button likebutton;
private ImageView versionlogo;
private ImageButton faq;
private ImageButton forum;
private ImageButton feedback;
private ImageButton rate;
private String likepath ="http://appkon.com/hdtvs/share.html";
private String likename = "分享";
private String lpath="" ;
private String lname="" ;
private String faqpath ="http://appkon.com/hdtvs/faq.html";
private String faqname ="常见问题";
private String forumpath= "http://appkon.com/forum/" ;
private String forumname = "APP论坛";
private String fqpath="";
private String fqname="";
private String frpath="";
private String frname="";
private String ratepath ="http://appkon.com/hdtvs/";
private String ratename="评价";
private String rpath="";
private String rname="";
private String feedbackpath ="http://appkon.com/hdtvs/feedback.html";
private String feedbackname="反馈问题";
private String fdname="";
private String fdpath="";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
backbutton=(Button) findViewById(R.id.back);
likebutton=(Button) findViewById(R.id.share);
faq =(ImageButton)findViewById(R.id.faqbutton);
forum =(ImageButton)findViewById(R.id.forumbutton);
feedback =(ImageButton)findViewById(R.id.feedbackbutton);
rate =(ImageButton)findViewById(R.id.ratebutton);
backbutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, HDtvs.class);
startActivity(intent);
About.this.finish();
}
});
likebutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Renrenframe.class);
startActivity(intent);
About.this.finish();
}
});
faq.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("fqpath",faqpath);
bundle.putString("fqname",faqname);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
feedback.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("fdpath",feedbackpath);
bundle.putString("fdname",feedbackname);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
rate.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("rpath",ratepath);
bundle.putString("rname",ratename);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
forum.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(About.this, Aboutframe.class);
Bundle bundle = new Bundle();
bundle.putString("frpath",forumpath);
bundle.putString("frname",forumname);
intent.putExtras(bundle);
startActivity(intent);
About.this.finish();
}
});
}
}
Aboutframe.java
public class Aboutframe extends Activity{
private TextView namebar;
private ImageButton likebutton;
private ImageButton backbutton;
private WebView aboutframe;
private String lpath ;
private String lname ;
private String fqpath;
private String fqname;
private String frpath;
private String frname;
private String rpath;
private String rname;
private String fdname;
private String fdpath;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutframe);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//remove title bar
backbutton=(ImageButton) findViewById(R.id.back);
likebutton=(ImageButton) findViewById(R.id.share);
aboutframe =(WebView)findViewById(R.id.aboutframe);
Intent intent=this.getIntent();
Bundle bunde = intent.getExtras();
lname = bunde.getString("lname");
lpath = bunde.getString("lpath");
fqname = bunde.getString("fqname");
fqpath = bunde.getString("fqpath");
frname = bunde.getString("frname");
frpath = bunde.getString("frpath");
rname = bunde.getString("rname");
rpath = bunde.getString("rpath");
fdname = bunde.getString("fdname");
fdpath = bunde.getString("fdpath");
if(lname != null&lpath!= null){
namebar.setText(lname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(lpath);
return true;
}
});
}
if(fqname != null&fqpath!= null){
namebar.setText(fqname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(fqpath);
return true;
}
});
}
if(frname != null&frpath!= null){
namebar.setText(frname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(frpath);
return true;
}
});
}
if(rname != null&rpath!= null){
namebar.setText(rname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(rpath);
return true;
}
});
}
if(fdname != null&fdpath!= null){
namebar.setText(fdname);
aboutframe.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(fdpath);
return true;
}
});
backbutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(Aboutframe.this, About.class);
startActivity(intent);
Aboutframe.this.finish();
}
});
likebutton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(Aboutframe.this, Renrenframe.class);
startActivity(intent);
Aboutframe.this.finish();
}
});
}
}
}
That error means your activity timed out.
I don't understand why you call:
aboutframe.setWebViewClient
multiple times. You can try to replace if's with if else's:
/*...*/
else if(frname != null&frpath!= null){
/*...*/
else if(rname != null&rpath!= null){
/*...*/
put all your code between
try
{
your Code here...
}
catch(NullPointerException e)
{
e.printStackTrace();
}
You better use && instead of &. The latter is "binary and", you want to use "logical and".