ここに問題があります。これの前に、すべてのコードをonCreate()の下に置きます。ただし、ロードに10秒以上かかり、画面が完全にロードされるまで空白の画面が表示されます。そのため、コードの一部をdoInBackgroundに移動しました。しかし、onCreate()では発生しない問題に直面しているので、今すぐコードを見てみましょう。
String photoURL1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.app_details);
tvDescription = (TextView)findViewById(R.id.tvDescription);
tvTitle = (TextView)findViewById(R.id.tvTitle);
tvDeveloper = (TextView)findViewById(R.id.tvDeveloper);
rbRating = (RatingBar)findViewById(R.id.rbRating);
ivLogo = (ImageView)findViewById(R.id.ivLogo);
ivPhoto1 = (ImageView)findViewById(R.id.ivPhoto1);
ivPhoto2 = (ImageView)findViewById(R.id.ivPhoto2);
ivPhoto3 = (ImageView)findViewById(R.id.ivPhoto3);
new loadPage().execute(null, null, null);
}
public class loadPage extends AsyncTask<String, Integer, Void> {
private ProgressDialog pdia;
@Override
protected void onPreExecute(){
super.onPreExecute();
pdia = new ProgressDialog(AppDetails.this);
pdia.setMessage("Loading...");
pdia.show();
}
@Override
protected Void doInBackground(String... aurl) {
SoapObject Request = new SoapObject (NAMESPACE, METHOD_NAME);
Request.addProperty("title", getIntent().getExtras().getString("xdaTitle"));
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(Request);
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
try
{
aht.call(SOAP_ACTION, soapEnvelope);
SoapObject resultString = (SoapObject) soapEnvelope.getResponse();
for(int i =0; i<resultString.getPropertyCount(); i++)
{
SoapObject array = (SoapObject) resultString .getProperty(i);
title = array.getProperty(1).toString();
developer = array.getProperty(3).toString();
//load images
photoURL1 = array.getProperty(5).toString(); //get logo url
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
}
}
catch(Exception e){
}
return null;
}
@Override
protected void onProgressUpdate(Integer... progress2) {
}
@Override
protected void onPostExecute(Void unused) {
tvTitle.setText(title);
tvDeveloper.setText(developer);
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
Bitmap bmLogo = LoadImage(photoURL1, bmOptions);
ivLogo.setImageBitmap(bmLogo);
pdia.dismiss();
}
ここに問題があります。
- 私のtvTitleは最初の3文字しか表示せず、tvDeveloperは7〜8文字しか表示しません(tvtitleとtvDeveloperはtextViewです)
- イメージローダーをdoInBackgroundからonPostExecuteに移動すると、強制的に閉じられます。
=======更新:このコードをどこに駐車すればよいですか?=================
MyI = new Intent(Intent.ACTION_VIEW);
MyI.setAction(android.content.Intent.ACTION_VIEW);
MyI.setDataAndType(Uri.parse("file:///sdcard/MaxApps/" + apkURL.toString()), "application/vnd.android.package-archive");
MyPI = PendingIntent.getActivity(getApplicationContext(), 0, MyI, 0);
MyNM = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(getApplicationContext(), AppDetails.class);
intent.putExtra("xdaTitle", title);
final PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
notification = new Notification(R.drawable.logo, "Downloading...", System.currentTimeMillis());
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
notification.contentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.downloadapk);
notification.contentIntent = pendingIntent;
notification.contentView.setImageViewResource(R.id.imgIcon, R.drawable.save);
notification.contentView.setTextViewText(R.id.tvText, "Downloading " + apkURL);
notification.contentView.setViewVisibility(R.id.pbStatus, View.VISIBLE);
notification.contentView.setProgressBar(R.id.pbStatus, 100, progress, false);
notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);