Mobile Application Development, Past Papers, UOS Main Campus

Mobile Application Development BSSE 7th Mid Past Paper 2016 – UOS Main Campus

ProgramBSSE
Semester7th
ExamMid Term
Year2016
AnswersSolved ✓

University of Sargodha main campus Mobile Application Development mid-term paper for BSSE 7th semester (Self and Regular), held on 18 November 2016 (22 marks, 1 hour 20 minutes). Retyped from the original paper, with solved answers below.

Paper set bySir Bilal IlyasName as written on the original paper

Solved answers

Q1 – Activity lifecycle (3)

Activity launched → onCreate() → onStart() → onResume() → activity running. Another activity comes in front → onPause() (returns via onResume()). Activity no longer visible → onStop(); when the user navigates back → onRestart() → onStart(). Activity finishing or destroyed by the system → onDestroy() → shut down. If the system needs memory, a stopped/paused app process can be killed and onCreate() runs again when the user returns.

Q2 – Conversions (3)

String s1 = obj.toString();          // a. Object to String  (or String.valueOf(obj))
String s2 = String.valueOf(num);     // b. int to String     (or Integer.toString(num))
int n = Integer.parseInt("123");     // c. String to int     (throws NumberFormatException if invalid)

Q3 – Context menu vs popup menu (4)

A context menu is a floating menu that appears on a long press on a view; its actions affect the selected item. A popup menu is a small list anchored to a view (usually shown on a normal click), used for overflow or extra actions.

// Context menu
registerForContextMenu(listView);
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, v, info);
    getMenuInflater().inflate(R.menu.context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.delete) { /* delete item */ return true; }
    return super.onContextItemSelected(item);
}

// Popup menu
button.setOnClickListener(v -> {
    PopupMenu popup = new PopupMenu(this, v);
    popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(item -> { /* handle */ return true; });
    popup.show();
});

Q4 – Validate the floating-label EditText (3)

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/nameLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Full Name">
    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/nameEdit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
private boolean validateName() {
    String name = nameEdit.getText().toString().trim();
    if (name.isEmpty()) {
        nameLayout.setError("Enter your full name");
        return false;
    }
    nameLayout.setError(null);   // clear the error
    return true;
}

Q5 – Android application framework

The application framework is the Java API layer that apps are built on, sitting above the native libraries and Android runtime (ART) and the Linux kernel. Its main components: Activity Manager (activity lifecycle and back stack), Window Manager, View System (UI widgets and layouts), Content Providers (share data between apps), Package Manager (installed apps), Resource Manager (strings, images, layouts), Notification Manager, Location Manager and Telephony Manager. Apps use these services through components: activities, services, broadcast receivers and content providers, connected by intents.

Q6 – Tabs with a pager adapter (4)

// activity_main.xml: Toolbar (@+id/toolbar), TabLayout (@+id/tabs), ViewPager (@+id/viewpager)
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("Tabs Assignment");

        ViewPager pager = findViewById(R.id.viewpager);
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        adapter.addFragment(new CalculatorFragment(), "CALCULATOR");
        adapter.addFragment(new FacebookFragment(), "FACEBOOK");
        pager.setAdapter(adapter);

        TabLayout tabs = findViewById(R.id.tabs);
        tabs.setupWithViewPager(pager);
    }
}

class ViewPagerAdapter extends FragmentPagerAdapter {
    private final List<Fragment> fragments = new ArrayList<>();
    private final List<String> titles = new ArrayList<>();
    ViewPagerAdapter(FragmentManager fm) { super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); }
    void addFragment(Fragment f, String title) { fragments.add(f); titles.add(title); }
    @Override public Fragment getItem(int position) { return fragments.get(position); }
    @Override public int getCount() { return fragments.size(); }
    @Override public CharSequence getPageTitle(int position) { return titles.get(position); }
}
Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.