質問

I have the following code that pulls a pdf document from a remote viewer to view:

package com.example.techvault;

import java.io.File;
import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

public class PDFFromServerActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_document);
        Intent in= getIntent(); // gets the previously created intent
        String url = in.getStringExtra("full_url");
        if (!url.startsWith("http://") && !url.startsWith("https://")){
            url = "http://ezdrawdocs.com" + url;
        }
        Log.d("pdf url: ",url);
        String extStorageDirectory = Environment.getExternalStorageDirectory()
        .toString();
        File folder = new File(extStorageDirectory, "pdf");
        folder.mkdir();
        File file = new File(folder, "Read.pdf");
        try {
            file.createNewFile();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        Downloader.DownloadFile(url, file);

        showPdf();
    }
    public void showPdf()
        {
            File file = new File(Environment.getExternalStorageDirectory()+"/pdf/Read.pdf");
            PackageManager packageManager = getPackageManager();
            Intent testIntent = new Intent(Intent.ACTION_VIEW);
            testIntent.setType("application/pdf");
            List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            Uri uri = Uri.fromFile(file);
            intent.setDataAndType(uri, "application/pdf");
            startActivity(intent);
        }
}

When the backarrow is selected it redirects to a blank screen. How can I control which activity to redirect to when backarrow is selected? Thanks

役に立ちましたか?

解決

You can define that in your manifest under the activity with

<meta-data
    android:name="android.support.PARENT_ACTIVITY"
    android:value="com.example.yourapp.SomeActivity" />

他のヒント

What you're doing here is implementing what I call a "Passthrough Activity" (an Activity that has no UI and immediately launches a different Activity)... I personally try to avoid them.

That said, what you need to do is call Activity.finish() after showPDF() in Activity.onCreate(). That will close your passthrough so that when you back out of the PDF viewer you will not come back to the passthrough.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top